11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst common = require('../common'); 41cb0ef41Sopenharmony_ciif (!common.hasCrypto) 51cb0ef41Sopenharmony_ci common.skip('missing crypto'); 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ciconst assert = require('assert'); 81cb0ef41Sopenharmony_ciconst { 91cb0ef41Sopenharmony_ci generateKeyPairSync, 101cb0ef41Sopenharmony_ci} = require('crypto'); 111cb0ef41Sopenharmony_ciconst { 121cb0ef41Sopenharmony_ci assertApproximateSize, 131cb0ef41Sopenharmony_ci testEncryptDecrypt, 141cb0ef41Sopenharmony_ci testSignVerify, 151cb0ef41Sopenharmony_ci pkcs1PubExp, 161cb0ef41Sopenharmony_ci pkcs8Exp, 171cb0ef41Sopenharmony_ci} = require('../common/crypto'); 181cb0ef41Sopenharmony_ci 191cb0ef41Sopenharmony_ci// To make the test faster, we will only test sync key generation once and 201cb0ef41Sopenharmony_ci// with a relatively small key. 211cb0ef41Sopenharmony_ci{ 221cb0ef41Sopenharmony_ci const ret = generateKeyPairSync('rsa', { 231cb0ef41Sopenharmony_ci publicExponent: 3, 241cb0ef41Sopenharmony_ci modulusLength: 512, 251cb0ef41Sopenharmony_ci publicKeyEncoding: { 261cb0ef41Sopenharmony_ci type: 'pkcs1', 271cb0ef41Sopenharmony_ci format: 'pem' 281cb0ef41Sopenharmony_ci }, 291cb0ef41Sopenharmony_ci privateKeyEncoding: { 301cb0ef41Sopenharmony_ci type: 'pkcs8', 311cb0ef41Sopenharmony_ci format: 'pem' 321cb0ef41Sopenharmony_ci } 331cb0ef41Sopenharmony_ci }); 341cb0ef41Sopenharmony_ci 351cb0ef41Sopenharmony_ci assert.strictEqual(Object.keys(ret).length, 2); 361cb0ef41Sopenharmony_ci const { publicKey, privateKey } = ret; 371cb0ef41Sopenharmony_ci 381cb0ef41Sopenharmony_ci assert.strictEqual(typeof publicKey, 'string'); 391cb0ef41Sopenharmony_ci assert.match(publicKey, pkcs1PubExp); 401cb0ef41Sopenharmony_ci assertApproximateSize(publicKey, 162); 411cb0ef41Sopenharmony_ci assert.strictEqual(typeof privateKey, 'string'); 421cb0ef41Sopenharmony_ci assert.match(privateKey, pkcs8Exp); 431cb0ef41Sopenharmony_ci assertApproximateSize(privateKey, 512); 441cb0ef41Sopenharmony_ci 451cb0ef41Sopenharmony_ci testEncryptDecrypt(publicKey, privateKey); 461cb0ef41Sopenharmony_ci testSignVerify(publicKey, privateKey); 471cb0ef41Sopenharmony_ci} 48