| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent b9039a5 commit aa4152a
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -319,6 +319,7 @@ MaybeLocal<Value> WritePrivateKey( | |||
| 319 | 319 | } | |
| 320 | 320 | } | |
| 321 | 321 | ||
| 322 | + MarkPopErrorOnReturn mark_pop_error_on_return; | ||
| 322 | 323 | bool err; | |
| 323 | 324 | ||
| 324 | 325 | PKEncodingType encoding_type = config.type_.ToChecked(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,41 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + | ||
| 4 | + // Test for https://github.com/nodejs/node/issues/40814 | ||
| 5 | + | ||
| 6 | + if (!common.hasCrypto) | ||
| 7 | + common.skip('missing crypto'); | ||
| 8 | + | ||
| 9 | + if (!common.hasOpenSSL3) | ||
| 10 | + common.skip('only openssl3'); // https://github.com/nodejs/node/pull/42793#issuecomment-1107491901 | ||
| 11 | + | ||
| 12 | + const assert = require('assert'); | ||
| 13 | + const crypto = require('crypto'); | ||
| 14 | + | ||
| 15 | + const { privateKey, publicKey } = crypto.generateKeyPairSync('rsa', { | ||
| 16 | + modulusLength: 2048, | ||
| 17 | + publicKeyEncoding: { | ||
| 18 | + type: 'spki', | ||
| 19 | + format: 'pem' | ||
| 20 | + }, | ||
| 21 | + privateKeyEncoding: { | ||
| 22 | + type: 'pkcs8', | ||
| 23 | + format: 'pem', | ||
| 24 | + cipher: 'aes-128-ecb', | ||
| 25 | + passphrase: 'abcdef' | ||
| 26 | + } | ||
| 27 | + }); | ||
| 28 | + assert.notStrictEqual(privateKey.toString(), ''); | ||
| 29 | + | ||
| 30 | + const msg = 'The quick brown fox jumps over the lazy dog'; | ||
| 31 | + | ||
| 32 | + const encryptedString = crypto.privateEncrypt({ | ||
| 33 | + key: privateKey, | ||
| 34 | + passphrase: 'abcdef' | ||
| 35 | + }, Buffer.from(msg)).toString('base64'); | ||
| 36 | + const decryptedString = crypto.publicDecrypt(publicKey, Buffer.from(encryptedString, 'base64')).toString(); | ||
| 37 | + console.log(`Encrypted: ${encryptedString}`); | ||
| 38 | + console.log(`Decrypted: ${decryptedString}`); | ||
| 39 | + | ||
| 40 | + assert.notStrictEqual(encryptedString, ''); | ||
| 41 | + assert.strictEqual(decryptedString, msg); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments