Skip to content
Open
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
3,434 changes: 3,434 additions & 0 deletions bun.lock

Large diffs are not rendered by default.

Binary file removed bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"specs": "bun --filter='react-native-quick-crypto' specs",
"bundle-install": "bun --filter='react-native-quick-crypto-example' bundle-install",
"pods": "bun --filter='react-native-quick-crypto-example' pods",
"start": "cd packages/example && bun start",
"start": "bun --cwd packages/example start",
"bootstrap": "bun install && bun pods",
"tsc": "bun --filter='*' typescript",
"lint": "bun --filter='*' lint",
Expand Down
4 changes: 2 additions & 2 deletions packages/example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ DEPENDENCIES:
- React-utils (from `../../../node_modules/react-native/ReactCommon/react/utils`)
- ReactCommon/turbomodule/core (from `../../../node_modules/react-native/ReactCommon`)
- "RNCCheckbox (from `../../../node_modules/@react-native-community/checkbox`)"
- RNScreens (from `../node_modules/react-native-screens`)
- RNScreens (from `../../../node_modules/react-native-screens`)
- Yoga (from `../../../node_modules/react-native/ReactCommon/yoga`)

SPEC REPOS:
Expand Down Expand Up @@ -596,7 +596,7 @@ EXTERNAL SOURCES:
RNCCheckbox:
:path: "../../../node_modules/@react-native-community/checkbox"
RNScreens:
:path: "../node_modules/react-native-screens"
:path: "../../../node_modules/react-native-screens"
Yoga:
:path: "../../../node_modules/react-native/ReactCommon/yoga"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = N99BE7M6KP;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = QuickCryptoExample/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
Expand Down Expand Up @@ -444,6 +445,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = N99BE7M6KP;
INFOPLIST_FILE = QuickCryptoExample/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
Expand Down
168 changes: 101 additions & 67 deletions packages/example/src/testing/tests/CipherTests/PublicCipherTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import type { KeyPairKey } from '../../../../../react-native-quick-crypto/src/Ci
import type { EncodingOptions } from '../../../../../react-native-quick-crypto/src/keys';
// import { PrivateKey } from 'sscrypto/node';

const message = 'Hello Node.js world!';

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

it('publicEncrypt/privateDecrypt', () => {
const { privateKey, publicKey } = crypto.generateKeyPairSync('rsa', {
modulusLength: 512,
publicKeyEncoding: {
type: 'pkcs1',
format: 'pem',
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem',
},
});
// it('publicEncrypt/privateDecrypt', () => {
// const { privateKey, publicKey } = crypto.generateKeyPairSync('rsa', {
// modulusLength: 512,
// publicKeyEncoding: {
// type: 'pkcs1',
// format: 'pem',
// },
// privateKeyEncoding: {
// type: 'pkcs8',
// format: 'pem',
// },
// });

testEncryptDecrypt(publicKey, privateKey);
});
// testEncryptDecrypt(publicKey, privateKey);
// });

// it('publicEncrypt/privateDecrypt with non-common exponent', () => {
// const { privateKey, publicKey } = crypto.generateKeyPairSync('rsa', {
// publicExponent: 3,
// modulusLength: 512,
// publicKeyEncoding: {
// type: 'pkcs1',
// format: 'pem',
// },
// privateKeyEncoding: {
// type: 'pkcs8',
// format: 'pem',
// },
// });

// testEncryptDecrypt(publicKey, privateKey);
// });

// it('publicEncrypt/privateDecrypt with passphrase', () => {
// const { privateKey, publicKey } = crypto.generateKeyPairSync('rsa', {
// modulusLength: 4096,
// publicKeyEncoding: {
// type: 'spki',
// format: 'pem',
// },
// privateKeyEncoding: {
// type: 'pkcs8',
// format: 'pem',
// cipher: 'aes-256-cbc',
// passphrase: 'top secret',
// },
// });

// const message = 'Hello RN world!';
// const plaintext = Buffer.from(message, 'utf8');
// const ciphertext = crypto.publicEncrypt(
// publicKey as EncodingOptions,
// plaintext,
// );
// const decrypted = crypto.privateDecrypt(
// { key: privateKey, passphrase: 'top secret' },
// ciphertext,
// );

// expect(decrypted.toString('utf-8')).to.equal(message);
// });

// it('passphrased private key without passphrase should throw', () => {
// const { privateKey, publicKey } = crypto.generateKeyPairSync('rsa', {
// modulusLength: 4096,
// publicKeyEncoding: {
// type: 'spki',
// format: 'pem',
// },
// privateKeyEncoding: {
// type: 'pkcs8',
// format: 'pem',
// cipher: 'aes-256-cbc',
// passphrase: 'top secret',
// },
// });

// try {
// testEncryptDecrypt(publicKey, privateKey);
// assert.fail();
// // eslint-disable-next-line @typescript-eslint/no-unused-vars
// } catch (_e) {
// // intentionally left blank
// }
// });

it('publicEncrypt/privateDecrypt with non-common exponent', () => {
it('#494 decryption error', () => {
const { privateKey, publicKey } = crypto.generateKeyPairSync('rsa', {
publicExponent: 3,
modulusLength: 512,
publicKeyEncoding: {
type: 'pkcs1',
Expand All @@ -92,59 +162,23 @@ describe('publicCipher', () => {
},
});

testEncryptDecrypt(publicKey, privateKey);
});

it('publicEncrypt/privateDecrypt with passphrase', () => {
const { privateKey, publicKey } = crypto.generateKeyPairSync('rsa', {
modulusLength: 4096,
publicKeyEncoding: {
type: 'spki',
format: 'pem',
const encryptedMessage = crypto.publicEncrypt(
{
key: publicKey,
padding: crypto.constants.RSA_PKCS1_PADDING,
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem',
cipher: 'aes-256-cbc',
passphrase: 'top secret',
},
});

const message = 'Hello RN world!';
const plaintext = Buffer.from(message, 'utf8');
const ciphertext = crypto.publicEncrypt(
publicKey as EncodingOptions,
plaintext,
Buffer.from(message, 'utf8')
);
const decrypted = crypto.privateDecrypt(
{ key: privateKey, passphrase: 'top secret' },
ciphertext,
);

expect(decrypted.toString('utf-8')).to.equal(message);
});

it('passphrased private key without passphrase should throw', () => {
const { privateKey, publicKey } = crypto.generateKeyPairSync('rsa', {
modulusLength: 4096,
publicKeyEncoding: {
type: 'spki',
format: 'pem',
const decryptedMessage = crypto.privateDecrypt(
{
key: privateKey,
padding: crypto.constants.RSA_PKCS1_PADDING,
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem',
cipher: 'aes-256-cbc',
passphrase: 'top secret',
},
});
encryptedMessage
);

try {
testEncryptDecrypt(publicKey, privateKey);
assert.fail();
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (_e) {
// intentionally left blank
}
});
console.log(encryptedMessage.toString('hex'));
expect(decryptedMessage.toString('utf8')).to.equal(message);
})
});
Loading