Skip to content

Commit ee69504

Browse files
committed
test: troubleshoot #494
1 parent 14d540b commit ee69504

File tree

6 files changed

+3540
-70
lines changed

6 files changed

+3540
-70
lines changed

bun.lock

Lines changed: 3434 additions & 0 deletions
Large diffs are not rendered by default.

bun.lockb

-527 KB
Binary file not shown.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"specs": "bun --filter='react-native-quick-crypto' specs",
77
"bundle-install": "bun --filter='react-native-quick-crypto-example' bundle-install",
88
"pods": "bun --filter='react-native-quick-crypto-example' pods",
9-
"start": "cd packages/example && bun start",
9+
"start": "bun --cwd packages/example start",
1010
"bootstrap": "bun install && bun pods",
1111
"tsc": "bun --filter='*' typescript",
1212
"lint": "bun --filter='*' lint",

packages/example/ios/Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ DEPENDENCIES:
496496
- React-utils (from `../../../node_modules/react-native/ReactCommon/react/utils`)
497497
- ReactCommon/turbomodule/core (from `../../../node_modules/react-native/ReactCommon`)
498498
- "RNCCheckbox (from `../../../node_modules/@react-native-community/checkbox`)"
499-
- RNScreens (from `../node_modules/react-native-screens`)
499+
- RNScreens (from `../../../node_modules/react-native-screens`)
500500
- Yoga (from `../../../node_modules/react-native/ReactCommon/yoga`)
501501

502502
SPEC REPOS:
@@ -596,7 +596,7 @@ EXTERNAL SOURCES:
596596
RNCCheckbox:
597597
:path: "../../../node_modules/@react-native-community/checkbox"
598598
RNScreens:
599-
:path: "../node_modules/react-native-screens"
599+
:path: "../../../node_modules/react-native-screens"
600600
Yoga:
601601
:path: "../../../node_modules/react-native/ReactCommon/yoga"
602602

packages/example/ios/QuickCryptoExample.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,7 @@
417417
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
418418
CLANG_ENABLE_MODULES = YES;
419419
CURRENT_PROJECT_VERSION = 1;
420+
DEVELOPMENT_TEAM = N99BE7M6KP;
420421
ENABLE_BITCODE = NO;
421422
INFOPLIST_FILE = QuickCryptoExample/Info.plist;
422423
LD_RUNPATH_SEARCH_PATHS = (
@@ -444,6 +445,7 @@
444445
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
445446
CLANG_ENABLE_MODULES = YES;
446447
CURRENT_PROJECT_VERSION = 1;
448+
DEVELOPMENT_TEAM = N99BE7M6KP;
447449
INFOPLIST_FILE = QuickCryptoExample/Info.plist;
448450
LD_RUNPATH_SEARCH_PATHS = (
449451
"$(inherited)",

packages/example/src/testing/tests/CipherTests/PublicCipherTests.ts

Lines changed: 101 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ import type { KeyPairKey } from '../../../../../react-native-quick-crypto/src/Ci
66
import type { EncodingOptions } from '../../../../../react-native-quick-crypto/src/keys';
77
// import { PrivateKey } from 'sscrypto/node';
88

9+
const message = 'Hello Node.js world!';
10+
911
// Tests that a key pair can be used for encryption / decryption.
1012
function testEncryptDecrypt(publicKey: KeyPairKey, privateKey: KeyPairKey) {
11-
const message = 'Hello Node.js world!';
1213
const plaintext = Buffer.from(message, 'utf8');
1314
for (const key of [publicKey, privateKey]) {
1415
// the EncodingOptions type is weird as shit, but it works.
@@ -62,25 +63,94 @@ describe('publicCipher', () => {
6263
// }
6364
// });
6465

65-
it('publicEncrypt/privateDecrypt', () => {
66-
const { privateKey, publicKey } = crypto.generateKeyPairSync('rsa', {
67-
modulusLength: 512,
68-
publicKeyEncoding: {
69-
type: 'pkcs1',
70-
format: 'pem',
71-
},
72-
privateKeyEncoding: {
73-
type: 'pkcs8',
74-
format: 'pem',
75-
},
76-
});
66+
// it('publicEncrypt/privateDecrypt', () => {
67+
// const { privateKey, publicKey } = crypto.generateKeyPairSync('rsa', {
68+
// modulusLength: 512,
69+
// publicKeyEncoding: {
70+
// type: 'pkcs1',
71+
// format: 'pem',
72+
// },
73+
// privateKeyEncoding: {
74+
// type: 'pkcs8',
75+
// format: 'pem',
76+
// },
77+
// });
7778

78-
testEncryptDecrypt(publicKey, privateKey);
79-
});
79+
// testEncryptDecrypt(publicKey, privateKey);
80+
// });
81+
82+
// it('publicEncrypt/privateDecrypt with non-common exponent', () => {
83+
// const { privateKey, publicKey } = crypto.generateKeyPairSync('rsa', {
84+
// publicExponent: 3,
85+
// modulusLength: 512,
86+
// publicKeyEncoding: {
87+
// type: 'pkcs1',
88+
// format: 'pem',
89+
// },
90+
// privateKeyEncoding: {
91+
// type: 'pkcs8',
92+
// format: 'pem',
93+
// },
94+
// });
95+
96+
// testEncryptDecrypt(publicKey, privateKey);
97+
// });
98+
99+
// it('publicEncrypt/privateDecrypt with passphrase', () => {
100+
// const { privateKey, publicKey } = crypto.generateKeyPairSync('rsa', {
101+
// modulusLength: 4096,
102+
// publicKeyEncoding: {
103+
// type: 'spki',
104+
// format: 'pem',
105+
// },
106+
// privateKeyEncoding: {
107+
// type: 'pkcs8',
108+
// format: 'pem',
109+
// cipher: 'aes-256-cbc',
110+
// passphrase: 'top secret',
111+
// },
112+
// });
113+
114+
// const message = 'Hello RN world!';
115+
// const plaintext = Buffer.from(message, 'utf8');
116+
// const ciphertext = crypto.publicEncrypt(
117+
// publicKey as EncodingOptions,
118+
// plaintext,
119+
// );
120+
// const decrypted = crypto.privateDecrypt(
121+
// { key: privateKey, passphrase: 'top secret' },
122+
// ciphertext,
123+
// );
124+
125+
// expect(decrypted.toString('utf-8')).to.equal(message);
126+
// });
127+
128+
// it('passphrased private key without passphrase should throw', () => {
129+
// const { privateKey, publicKey } = crypto.generateKeyPairSync('rsa', {
130+
// modulusLength: 4096,
131+
// publicKeyEncoding: {
132+
// type: 'spki',
133+
// format: 'pem',
134+
// },
135+
// privateKeyEncoding: {
136+
// type: 'pkcs8',
137+
// format: 'pem',
138+
// cipher: 'aes-256-cbc',
139+
// passphrase: 'top secret',
140+
// },
141+
// });
142+
143+
// try {
144+
// testEncryptDecrypt(publicKey, privateKey);
145+
// assert.fail();
146+
// // eslint-disable-next-line @typescript-eslint/no-unused-vars
147+
// } catch (_e) {
148+
// // intentionally left blank
149+
// }
150+
// });
80151

81-
it('publicEncrypt/privateDecrypt with non-common exponent', () => {
152+
it('#494 decryption error', () => {
82153
const { privateKey, publicKey } = crypto.generateKeyPairSync('rsa', {
83-
publicExponent: 3,
84154
modulusLength: 512,
85155
publicKeyEncoding: {
86156
type: 'pkcs1',
@@ -92,59 +162,23 @@ describe('publicCipher', () => {
92162
},
93163
});
94164

95-
testEncryptDecrypt(publicKey, privateKey);
96-
});
97-
98-
it('publicEncrypt/privateDecrypt with passphrase', () => {
99-
const { privateKey, publicKey } = crypto.generateKeyPairSync('rsa', {
100-
modulusLength: 4096,
101-
publicKeyEncoding: {
102-
type: 'spki',
103-
format: 'pem',
165+
const encryptedMessage = crypto.publicEncrypt(
166+
{
167+
key: publicKey,
168+
padding: crypto.constants.RSA_PKCS1_PADDING,
104169
},
105-
privateKeyEncoding: {
106-
type: 'pkcs8',
107-
format: 'pem',
108-
cipher: 'aes-256-cbc',
109-
passphrase: 'top secret',
110-
},
111-
});
112-
113-
const message = 'Hello RN world!';
114-
const plaintext = Buffer.from(message, 'utf8');
115-
const ciphertext = crypto.publicEncrypt(
116-
publicKey as EncodingOptions,
117-
plaintext,
170+
Buffer.from(message, 'utf8')
118171
);
119-
const decrypted = crypto.privateDecrypt(
120-
{ key: privateKey, passphrase: 'top secret' },
121-
ciphertext,
122-
);
123-
124-
expect(decrypted.toString('utf-8')).to.equal(message);
125-
});
126172

127-
it('passphrased private key without passphrase should throw', () => {
128-
const { privateKey, publicKey } = crypto.generateKeyPairSync('rsa', {
129-
modulusLength: 4096,
130-
publicKeyEncoding: {
131-
type: 'spki',
132-
format: 'pem',
173+
const decryptedMessage = crypto.privateDecrypt(
174+
{
175+
key: privateKey,
176+
padding: crypto.constants.RSA_PKCS1_PADDING,
133177
},
134-
privateKeyEncoding: {
135-
type: 'pkcs8',
136-
format: 'pem',
137-
cipher: 'aes-256-cbc',
138-
passphrase: 'top secret',
139-
},
140-
});
178+
encryptedMessage
179+
);
141180

142-
try {
143-
testEncryptDecrypt(publicKey, privateKey);
144-
assert.fail();
145-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
146-
} catch (_e) {
147-
// intentionally left blank
148-
}
149-
});
181+
console.log(encryptedMessage.toString('hex'));
182+
expect(decryptedMessage.toString('utf8')).to.equal(message);
183+
})
150184
});

0 commit comments

Comments
 (0)