mirror of
https://github.com/openpgpjs/openpgpjs.git
synced 2025-06-23 14:42:32 +00:00
Merge branch 'main' into v6
This commit is contained in:
commit
d4fd9c8d43
@ -114,8 +114,15 @@ export async function encrypt(data, n, e) {
|
|||||||
* @async
|
* @async
|
||||||
*/
|
*/
|
||||||
export async function decrypt(data, n, e, d, p, q, u, randomPayload) {
|
export async function decrypt(data, n, e, d, p, q, u, randomPayload) {
|
||||||
if (util.getNodeCrypto()) {
|
// Node v18.19.1, 20.11.1 and 21.6.2 have disabled support for PKCS#1 decryption,
|
||||||
return nodeDecrypt(data, n, e, d, p, q, u, randomPayload);
|
// and we want to avoid checking the error type to decide if the random payload
|
||||||
|
// should indeed be returned.
|
||||||
|
if (util.getNodeCrypto() && !randomPayload) {
|
||||||
|
try {
|
||||||
|
return await nodeDecrypt(data, n, e, d, p, q, u);
|
||||||
|
} catch (err) {
|
||||||
|
util.printDebugError(err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return bnDecrypt(data, n, e, d, p, q, u, randomPayload);
|
return bnDecrypt(data, n, e, d, p, q, u, randomPayload);
|
||||||
}
|
}
|
||||||
@ -350,16 +357,13 @@ async function bnEncrypt(data, n, e) {
|
|||||||
return data.modExp(e, n).toUint8Array('be', n.byteLength());
|
return data.modExp(e, n).toUint8Array('be', n.byteLength());
|
||||||
}
|
}
|
||||||
|
|
||||||
async function nodeDecrypt(data, n, e, d, p, q, u, randomPayload) {
|
async function nodeDecrypt(data, n, e, d, p, q, u) {
|
||||||
const jwk = await privateToJWK(n, e, d, p, q, u);
|
const jwk = await privateToJWK(n, e, d, p, q, u);
|
||||||
const key = { key: jwk, format: 'jwk' , type: 'pkcs1', padding: nodeCrypto.constants.RSA_PKCS1_PADDING };
|
const key = { key: jwk, format: 'jwk' , type: 'pkcs1', padding: nodeCrypto.constants.RSA_PKCS1_PADDING };
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return new Uint8Array(nodeCrypto.privateDecrypt(key, data));
|
return new Uint8Array(nodeCrypto.privateDecrypt(key, data));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (randomPayload) {
|
|
||||||
return randomPayload;
|
|
||||||
}
|
|
||||||
throw new Error('Decryption error');
|
throw new Error('Decryption error');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1391,7 +1391,7 @@ DAAKCRDyMVUMT0fjjlnQAQDFHUs6TIcxrNTtEZFjUFm1M0PJ1Dng/cDW4xN80fsn
|
|||||||
],
|
],
|
||||||
config
|
config
|
||||||
});
|
});
|
||||||
expect(openpgp.decrypt({
|
await expect(openpgp.decrypt({
|
||||||
message: await openpgp.readMessage({ armoredMessage: message_with_notation }),
|
message: await openpgp.readMessage({ armoredMessage: message_with_notation }),
|
||||||
decryptionKeys: privKey,
|
decryptionKeys: privKey,
|
||||||
verificationKeys: privKey,
|
verificationKeys: privKey,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user