Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: privateDecrypt() #504

Open
wants to merge 1 commit into
base: 0.x
Choose a base branch
from
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
Binary file modified example/bun.lockb
Binary file not shown.
4 changes: 2 additions & 2 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ PODS:
- react-native-quick-base64 (2.1.2):
- RCT-Folly (= 2021.07.22.00)
- React-Core
- react-native-quick-crypto (0.7.5):
- react-native-quick-crypto (0.7.6):
- OpenSSL-Universal
- RCT-Folly (= 2021.07.22.00)
- React
Expand Down Expand Up @@ -628,7 +628,7 @@ SPEC CHECKSUMS:
React-logger: 8edc785c47c8686c7962199a307015e2ce9a0e4f
react-native-fast-encoder: 6f59e9b08e2bc5a8bf1f36e1630cdcfd66dd18af
react-native-quick-base64: 61228d753294ae643294a75fece8e0e80b7558a6
react-native-quick-crypto: df499480b8be25084f8789752ffb0f1d9d1b4363
react-native-quick-crypto: 03d888b32a7d58adfe93926ee226c1adc5519c6e
react-native-safe-area-context: ab8f4a3d8180913bd78ae75dd599c94cce3d5e9a
React-NativeModulesApple: b6868ee904013a7923128892ee4a032498a1024a
React-perflogger: 31ea61077185eb1428baf60c0db6e2886f141a5a
Expand Down
64 changes: 32 additions & 32 deletions example/ios/QuickCryptoExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

/* Begin PBXBuildFile section */
00E356F31AD99517003FC87E /* QuickCryptoExampleTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 00E356F21AD99517003FC87E /* QuickCryptoExampleTests.m */; };
0C80B921A6F3F58F76C31292 /* libPods-QuickCryptoExample.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5DCACB8F33CDC322A6C60F78 /* libPods-QuickCryptoExample.a */; };
13B07FBC1A68108700A75B9A /* AppDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB01A68108700A75B9A /* AppDelegate.mm */; };
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; };
13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; };
81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */; };
CAC2F3DD056771524597783F /* libPods-QuickCryptoExample.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 85D796C24C2B0E5C1EADA1A1 /* libPods-QuickCryptoExample.a */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand All @@ -35,11 +35,11 @@
13B07FB51A68108700A75B9A /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Images.xcassets; path = QuickCryptoExample/Images.xcassets; sourceTree = "<group>"; };
13B07FB61A68108700A75B9A /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = QuickCryptoExample/Info.plist; sourceTree = "<group>"; };
13B07FB71A68108700A75B9A /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = QuickCryptoExample/main.m; sourceTree = "<group>"; };
3B4392A12AC88292D35C810B /* Pods-QuickCryptoExample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-QuickCryptoExample.debug.xcconfig"; path = "Target Support Files/Pods-QuickCryptoExample/Pods-QuickCryptoExample.debug.xcconfig"; sourceTree = "<group>"; };
5709B34CF0A7D63546082F79 /* Pods-QuickCryptoExample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-QuickCryptoExample.release.xcconfig"; path = "Target Support Files/Pods-QuickCryptoExample/Pods-QuickCryptoExample.release.xcconfig"; sourceTree = "<group>"; };
5DCACB8F33CDC322A6C60F78 /* libPods-QuickCryptoExample.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-QuickCryptoExample.a"; sourceTree = BUILT_PRODUCTS_DIR; };
38CA0E7A0B1B758A9517B9C8 /* Pods-QuickCryptoExample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-QuickCryptoExample.debug.xcconfig"; path = "Target Support Files/Pods-QuickCryptoExample/Pods-QuickCryptoExample.debug.xcconfig"; sourceTree = "<group>"; };
81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = LaunchScreen.storyboard; path = QuickCryptoExample/LaunchScreen.storyboard; sourceTree = "<group>"; };
85D796C24C2B0E5C1EADA1A1 /* libPods-QuickCryptoExample.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-QuickCryptoExample.a"; sourceTree = BUILT_PRODUCTS_DIR; };
ED297162215061F000B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; };
FF0CBA909073CA88460ECDBA /* Pods-QuickCryptoExample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-QuickCryptoExample.release.xcconfig"; path = "Target Support Files/Pods-QuickCryptoExample/Pods-QuickCryptoExample.release.xcconfig"; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand All @@ -54,7 +54,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
0C80B921A6F3F58F76C31292 /* libPods-QuickCryptoExample.a in Frameworks */,
CAC2F3DD056771524597783F /* libPods-QuickCryptoExample.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -95,7 +95,7 @@
isa = PBXGroup;
children = (
ED297162215061F000B7C4FE /* JavaScriptCore.framework */,
5DCACB8F33CDC322A6C60F78 /* libPods-QuickCryptoExample.a */,
85D796C24C2B0E5C1EADA1A1 /* libPods-QuickCryptoExample.a */,
);
name = Frameworks;
sourceTree = "<group>";
Expand Down Expand Up @@ -134,8 +134,8 @@
BBD78D7AC51CEA395F1C20DB /* Pods */ = {
isa = PBXGroup;
children = (
3B4392A12AC88292D35C810B /* Pods-QuickCryptoExample.debug.xcconfig */,
5709B34CF0A7D63546082F79 /* Pods-QuickCryptoExample.release.xcconfig */,
38CA0E7A0B1B758A9517B9C8 /* Pods-QuickCryptoExample.debug.xcconfig */,
FF0CBA909073CA88460ECDBA /* Pods-QuickCryptoExample.release.xcconfig */,
);
path = Pods;
sourceTree = "<group>";
Expand Down Expand Up @@ -165,14 +165,14 @@
isa = PBXNativeTarget;
buildConfigurationList = 13B07F931A680F5B00A75B9A /* Build configuration list for PBXNativeTarget "QuickCryptoExample" */;
buildPhases = (
C38B50BA6285516D6DCD4F65 /* [CP] Check Pods Manifest.lock */,
E13508F381CAE720A89E8BD5 /* [CP] Check Pods Manifest.lock */,
FD10A7F022414F080027D42C /* Start Packager */,
13B07F871A680F5B00A75B9A /* Sources */,
13B07F8C1A680F5B00A75B9A /* Frameworks */,
13B07F8E1A680F5B00A75B9A /* Resources */,
00DD1BFF1BD5951E006B06BC /* Bundle React Native code and images */,
00EEFC60759A1932668264C0 /* [CP] Embed Pods Frameworks */,
E235C05ADACE081382539298 /* [CP] Copy Pods Resources */,
B778CF800A898BCDAF9093A6 /* [CP] Embed Pods Frameworks */,
26CA66DCE8EF8EF2E997ABCF /* [CP] Copy Pods Resources */,
);
buildRules = (
);
Expand Down Expand Up @@ -255,7 +255,24 @@
shellPath = /bin/sh;
shellScript = "set -e\n\nWITH_ENVIRONMENT=\"../node_modules/react-native/scripts/xcode/with-environment.sh\"\nREACT_NATIVE_XCODE=\"../node_modules/react-native/scripts/react-native-xcode.sh\"\n\n/bin/sh -c \"$WITH_ENVIRONMENT $REACT_NATIVE_XCODE\"\n";
};
00EEFC60759A1932668264C0 /* [CP] Embed Pods Frameworks */ = {
26CA66DCE8EF8EF2E997ABCF /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-QuickCryptoExample/Pods-QuickCryptoExample-resources-${CONFIGURATION}-input-files.xcfilelist",
);
name = "[CP] Copy Pods Resources";
outputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-QuickCryptoExample/Pods-QuickCryptoExample-resources-${CONFIGURATION}-output-files.xcfilelist",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-QuickCryptoExample/Pods-QuickCryptoExample-resources.sh\"\n";
showEnvVarsInLog = 0;
};
B778CF800A898BCDAF9093A6 /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
Expand All @@ -272,7 +289,7 @@
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-QuickCryptoExample/Pods-QuickCryptoExample-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
C38B50BA6285516D6DCD4F65 /* [CP] Check Pods Manifest.lock */ = {
E13508F381CAE720A89E8BD5 /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
Expand All @@ -294,23 +311,6 @@
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
showEnvVarsInLog = 0;
};
E235C05ADACE081382539298 /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-QuickCryptoExample/Pods-QuickCryptoExample-resources-${CONFIGURATION}-input-files.xcfilelist",
);
name = "[CP] Copy Pods Resources";
outputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-QuickCryptoExample/Pods-QuickCryptoExample-resources-${CONFIGURATION}-output-files.xcfilelist",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-QuickCryptoExample/Pods-QuickCryptoExample-resources.sh\"\n";
showEnvVarsInLog = 0;
};
FD10A7F022414F080027D42C /* Start Packager */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -412,7 +412,7 @@
};
13B07F941A680F5B00A75B9A /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 3B4392A12AC88292D35C810B /* Pods-QuickCryptoExample.debug.xcconfig */;
baseConfigurationReference = 38CA0E7A0B1B758A9517B9C8 /* Pods-QuickCryptoExample.debug.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
Expand Down Expand Up @@ -489,7 +489,7 @@
};
13B07F951A680F5B00A75B9A /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 5709B34CF0A7D63546082F79 /* Pods-QuickCryptoExample.release.xcconfig */;
baseConfigurationReference = FF0CBA909073CA88460ECDBA /* Pods-QuickCryptoExample.release.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
Expand Down
126 changes: 63 additions & 63 deletions example/src/testing/tests/CipherTests/PublicCipherTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,73 +78,73 @@ describe('publicCipher', () => {
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',
},
});
// 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);
});
// 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',
},
});
// 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,
);
// 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);
});
// 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',
},
});
// 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
}
});
// try {
// testEncryptDecrypt(publicKey, privateKey);
// assert.fail();
// // eslint-disable-next-line @typescript-eslint/no-unused-vars
// } catch (_e) {
// // intentionally left blank
// }
// });
});
6 changes: 4 additions & 2 deletions ios/QuickCrypto.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.4;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -208,7 +208,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.4;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
VALIDATE_PRODUCT = YES;
Expand All @@ -224,6 +224,7 @@
"$(SRCROOT)/../../../React",
"$(SRCROOT)/../../react-native/React",
);
IPHONEOS_DEPLOYMENT_TARGET = 12.4;
LIBRARY_SEARCH_PATHS = "$(inherited)";
OTHER_LDFLAGS = "-ObjC";
PRODUCT_NAME = QuickCrypto;
Expand All @@ -240,6 +241,7 @@
"$(SRCROOT)/../../../React",
"$(SRCROOT)/../../react-native/React",
);
IPHONEOS_DEPLOYMENT_TARGET = 12.4;
LIBRARY_SEARCH_PATHS = "$(inherited)";
OTHER_LDFLAGS = "-ObjC";
PRODUCT_NAME = QuickCrypto;
Expand Down
2 changes: 1 addition & 1 deletion react-native-quick-crypto.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Pod::Spec.new do |s|
s.pod_target_xcconfig = {
"USE_HEADERMAP" => "YES",
"CLANG_CXX_LANGUAGE_STANDARD" => "c++20",
"HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/ReactCommon\" \"$(PODS_TARGET_SRCROOT)\" \"$(PODS_ROOT)/boost\" \"$(PODS_ROOT)/boost-for-react-native\" \"$(PODS_ROOT)/DoubleConversion\" \"$(PODS_ROOT)/Headers/Private/React-Core\" "
"HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)\" \"$(PODS_TARGET_SRCROOT)/React\" \"$(PODS_TARGET_SRCROOT)/ReactCommon\" \"$(PODS_ROOT)/boost\" \"$(PODS_ROOT)/boost-for-react-native\" \"$(PODS_ROOT)/DoubleConversion\" \"$(PODS_ROOT)/Headers/Private/React-Core\" "
}
s.dependency "React"
s.dependency "React-Core"
Expand Down
Loading