Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions example/src/tests/keys/public_cipher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1004,6 +1004,45 @@ test(
},
);

// --- Node.js Cross-Compatibility Test (issue #950) ---

test(
SUITE,
'privateDecrypt with Node.js default OAEP (sha1) ciphertext',
() => {
const privateKey = createPrivateKey({
key: Buffer.from(pkcs8),
format: 'der',
type: 'pkcs8',
});

// Ciphertext generated by Node.js crypto.publicEncrypt with default OAEP
// (sha1 hash, no oaepHash option specified)
const nodeEncrypted = Buffer.from(
'80472e57fbbfb952f5eeb24b9342634b9b2c50f9b8077254da41f9f620d0f195' +
'9fa4881d53dbd68949955055d7ff58728379c6a0c0f41efa92a54a4f087970f2' +
'dc06fb9a26d3489006b69fc8b0cae9818fa8d3e13001b6c758385e48a8ac7abb' +
'535c61e8e0b7eb7dc74c01834b8e464ab5f9799088b0ab0068e2781b8b11ef05' +
'12b544ae68ab3c76db41044ebde21077ec46111b47dd60ed55093cdecf14b8de' +
'e771df62e92f3fc6fe44500ee1e852ec6fd27cf43d8a4cf84a699e25606e0afb' +
'0c4de353ab88159cc0e39b81a30c74ff4b092abad5bb07bf58b3bde7241fe85d' +
'cb2bb8b0fbd9808e5d847342ab3ad2f06d210910d042156c3f2632876ebc7f4b',
'hex',
);

// Decrypt with default OAEP (should now use sha1, matching Node.js)
const decrypted = privateDecrypt(
{
key: privateKey,
padding: constants.RSA_PKCS1_OAEP_PADDING,
},
nodeEncrypted,
);

expect(decrypted.toString('utf-8')).to.equal('Hello, RSA-OAEP!');
},
);

test(SUITE, 'publicEncrypt/privateDecrypt are inverses', () => {
const publicKey = createPublicKey({
key: Buffer.from(spki),
Expand Down
4 changes: 2 additions & 2 deletions packages/react-native-quick-crypto/src/keys/publicCipher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export function publicEncrypt(
const rsaCipher: RsaCipher = NitroModules.createHybridObject('RsaCipher');
const data = toAB(buffer);
const paddingMode = padding ?? constants.RSA_PKCS1_OAEP_PADDING;
const hashAlgorithm = oaepHash || 'SHA-256';
const hashAlgorithm = oaepHash || 'sha1';

try {
const encrypted = rsaCipher.encrypt(
Expand Down Expand Up @@ -232,7 +232,7 @@ export function privateDecrypt(
const rsaCipher: RsaCipher = NitroModules.createHybridObject('RsaCipher');
const data = toAB(buffer);
const paddingMode = padding ?? constants.RSA_PKCS1_OAEP_PADDING;
const hashAlgorithm = oaepHash || 'SHA-256';
const hashAlgorithm = oaepHash || 'sha1';

try {
const decrypted = rsaCipher.privateDecrypt(
Expand Down
Loading