From e8ab3c955605266bd42875e2372269304c98f0fe Mon Sep 17 00:00:00 2001 From: qiaozzzh Date: Thu, 22 Dec 2022 10:37:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E8=A7=A3=E5=AF=86=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E5=A5=97=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: qiaozzzh --- .../asymmetric/publicAsymmetricCallback.js | 82 ++++++++----------- .../asymmetric/publicAsymmetricPromise.js | 38 ++++----- 2 files changed, 47 insertions(+), 73 deletions(-) diff --git a/security/cryptoFramework/js_api_test_one/src/main/js/test/utils/asymmetric/publicAsymmetricCallback.js b/security/cryptoFramework/js_api_test_one/src/main/js/test/utils/asymmetric/publicAsymmetricCallback.js index e51dc476c..a893c991d 100644 --- a/security/cryptoFramework/js_api_test_one/src/main/js/test/utils/asymmetric/publicAsymmetricCallback.js +++ b/security/cryptoFramework/js_api_test_one/src/main/js/test/utils/asymmetric/publicAsymmetricCallback.js @@ -217,8 +217,7 @@ async function generateAsySecret(generator, priKey, pubKey) { async function encryptAndDecryptNormalProcess(asyAlgoName, cipherAlgoName) { var globalCipherText; - var globalPubKey; - var globalPriKey; + var globalRsaKeyPair; var globalText = "This is a cipher test"; var input = { data: stringTouInt8Array(globalText) }; var encryptMode = cryptoFramework.CryptoMode.ENCRYPT_MODE; @@ -235,12 +234,11 @@ async function encryptAndDecryptNormalProcess(asyAlgoName, cipherAlgoName) { generateAsyKeyPair(rsaGenerator) .then((rsaKeyPair) => { expect(rsaKeyPair != null).assertTrue(); - globalPubKey = rsaKeyPair.pubKey; - globalPriKey = rsaKeyPair.priKey; + globalRsaKeyPair = rsaKeyPair; return initCipher( cipherGeneratorEncrypt, encryptMode, - globalPubKey, + globalRsaKeyPair.pubKey, null ); }) @@ -257,7 +255,7 @@ async function encryptAndDecryptNormalProcess(asyAlgoName, cipherAlgoName) { return initCipher( cipherGeneratorDecrypt, decryptMode, - globalPriKey, + globalRsaKeyPair.priKey, null ); }) @@ -292,8 +290,7 @@ async function encryptAndDecryptNormalProcess(asyAlgoName, cipherAlgoName) { } async function signAndVerifyNormalProcess(asyAlgoName, signVerifyAlgoName) { - var globalPubKey; - var globalPriKey; + var globalRsaKeyPair; var globalSignBlob; var globalText = "This is a sign test"; var input = { data: stringTouInt8Array(globalText) }; @@ -309,9 +306,8 @@ async function signAndVerifyNormalProcess(asyAlgoName, signVerifyAlgoName) { generateAsyKeyPair(rsaGenerator) .then((rsaKeyPair) => { expect(rsaKeyPair != null).assertTrue(); - globalPubKey = rsaKeyPair.pubKey; - globalPriKey = rsaKeyPair.priKey; - return initSign(signGenerator, globalPriKey); + globalRsaKeyPair = rsaKeyPair; + return initSign(signGenerator, globalRsaKeyPair.priKey); }) .then((initData) => { expect(initData === "init success").assertTrue(); @@ -325,7 +321,7 @@ async function signAndVerifyNormalProcess(asyAlgoName, signVerifyAlgoName) { expect(finalOutput != null).assertTrue(); globalSignBlob = finalOutput; console.log("signOutput: " + uInt8ArrayToShowStr(globalSignBlob.data)); - return initVerify(verifyGenerator, globalPubKey); + return initVerify(verifyGenerator, globalRsaKeyPair.pubKey); }) .then((initData) => { expect(initData === "init success").assertTrue(); @@ -403,8 +399,7 @@ async function createAsyKeyAgreementFail(ECDHAlgoName) { } async function keyAgreementProcess(ECDHAlgoName) { - var globalPubKey; - var globalPriKey; + var globalRsaKeyPair; return new Promise((resolve, reject) => { var rsaGenerator = createAsyKeyGenerator(ECDHAlgoName); @@ -415,9 +410,8 @@ async function keyAgreementProcess(ECDHAlgoName) { generateAsyKeyPair(rsaGenerator) .then((rsaKeyPair) => { expect(rsaKeyPair != null).assertTrue(); - globalPubKey = rsaKeyPair.pubKey; - globalPriKey = rsaKeyPair.priKey; - return generateAsySecret(globalECDHData, globalPriKey, globalPubKey); + globalRsaKeyPair = rsaKeyPair; + return generateAsySecret(globalECDHData, globalRsaKeyPair.priKey, globalRsaKeyPair.pubKey); }) .then((result) => { console.warn("result data is " + uInt8ArrayToShowStr(result.data)); @@ -432,8 +426,7 @@ async function keyAgreementProcess(ECDHAlgoName) { } async function keyAgreementProcessFail(ECDHAlgoName, ECDHAlgoName1) { - var globalPubKey; - var globalPriKey; + var globalRsaKeyPair; return new Promise((resolve, reject) => { var rsaGenerator = createAsyKeyGenerator(ECDHAlgoName); @@ -444,9 +437,8 @@ async function keyAgreementProcessFail(ECDHAlgoName, ECDHAlgoName1) { generateAsyKeyPair(rsaGenerator) .then((rsaKeyPair) => { expect(rsaKeyPair != null).assertTrue(); - globalPubKey = rsaKeyPair.pubKey; - globalPriKey = rsaKeyPair.priKey; - return generateAsySecret(globalECDHData, globalPriKey, globalPubKey); + globalRsaKeyPair = rsaKeyPair; + return generateAsySecret(globalECDHData, globalRsaKeyPair.priKey, globalRsaKeyPair.pubKey); }) .then((result) => { console.warn("result data is " + uInt8ArrayToShowStr(result.data)); @@ -461,8 +453,7 @@ async function keyAgreementProcessFail(ECDHAlgoName, ECDHAlgoName1) { } async function keyAgreementProcessParameterException(ECDHAlgoName) { - var globalPubKey; - var globalPriKey; + var globalRsaKeyPair; return new Promise((resolve, reject) => { var rsaGenerator = createAsyKeyGenerator(ECDHAlgoName); @@ -473,8 +464,7 @@ async function keyAgreementProcessParameterException(ECDHAlgoName) { generateAsyKeyPair(rsaGenerator) .then((rsaKeyPair) => { expect(rsaKeyPair != null).assertTrue(); - globalPubKey = rsaKeyPair.pubKey; - globalPriKey = rsaKeyPair.priKey; + globalRsaKeyPair = rsaKeyPair; return generateAsySecret(globalECDHData, null, null); }) .then((result) => { @@ -487,9 +477,8 @@ async function keyAgreementProcessParameterException(ECDHAlgoName) { generateAsyKeyPair(rsaGenerator) .then((rsaKeyPair) => { expect(rsaKeyPair != null).assertTrue(); - globalPubKey = rsaKeyPair.pubKey; - globalPriKey = rsaKeyPair.priKey; - return generateAsySecret(globalECDHData, globalPubKey, null); + globalRsaKeyPair = rsaKeyPair; + return generateAsySecret(globalECDHData, globalRsaKeyPair.pubKey, null); }) .then((result) => { console.warn("result data is " + uInt8ArrayToShowStr(result.data)); @@ -501,9 +490,8 @@ async function keyAgreementProcessParameterException(ECDHAlgoName) { generateAsyKeyPair(rsaGenerator) .then((rsaKeyPair) => { expect(rsaKeyPair != null).assertTrue(); - globalPubKey = rsaKeyPair.pubKey; - globalPriKey = rsaKeyPair.priKey; - return generateAsySecret(globalECDHData, null, globalPriKey); + globalRsaKeyPair = rsaKeyPair; + return generateAsySecret(globalECDHData, null, globalRsaKeyPair.priKey); }) .then((result) => { console.warn("result data is " + uInt8ArrayToShowStr(result.data)); @@ -531,8 +519,7 @@ async function createAsyKeyGeneratorFail(asyAlgoName) { async function encryptAndDecryptNormalProcessSuperdata(asyAlgoName, cipherAlgoName, globalTextLen) { var globalCipherText; - var globalPubKey; - var globalPriKey; + var globalRsaKeyPair; var globalText; var i; var encryptMode = cryptoFramework.CryptoMode.ENCRYPT_MODE; @@ -554,12 +541,11 @@ async function encryptAndDecryptNormalProcessSuperdata(asyAlgoName, cipherAlgoNa generateAsyKeyPair(rsaGenerator) .then((rsaKeyPair) => { expect(rsaKeyPair != null).assertTrue(); - globalPubKey = rsaKeyPair.pubKey; - globalPriKey = rsaKeyPair.priKey; + globalRsaKeyPair = rsaKeyPair; return initCipher( cipherGeneratorEncrypt, encryptMode, - globalPubKey, + globalRsaKeyPair.pubKey, null ); }) @@ -576,7 +562,7 @@ async function encryptAndDecryptNormalProcessSuperdata(asyAlgoName, cipherAlgoNa return initCipher( cipherGeneratorDecrypt, decryptMode, - globalPriKey, + globalRsaKeyPair.priKey, null ); }) @@ -612,8 +598,7 @@ async function encryptAndDecryptNormalProcessSuperdata(asyAlgoName, cipherAlgoNa async function signAndVerifyNormalProcessSuperdata(asyAlgoName, signVerifyAlgoName, globalTextLen) { var globalSignBlob; - var globalPubKey; - var globalPriKey; + var globalRsaKeyPair; var globalText; var i; var t = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefhijklmnopqrstuvwxyz",n = t.length,s=""; @@ -633,9 +618,8 @@ async function signAndVerifyNormalProcessSuperdata(asyAlgoName, signVerifyAlgoNa generateAsyKeyPair(rsaGenerator) .then((rsaKeyPair) => { expect(rsaKeyPair != null).assertTrue(); - globalPubKey = rsaKeyPair.pubKey; - globalPriKey = rsaKeyPair.priKey; - return initSign(signGenerator, globalPriKey); + globalRsaKeyPair = rsaKeyPair; + return initSign(signGenerator, globalRsaKeyPair.priKey); }) .then((initData) => { expect(initData === "init success").assertTrue(); @@ -649,7 +633,7 @@ async function signAndVerifyNormalProcessSuperdata(asyAlgoName, signVerifyAlgoNa expect(finalOutput != null).assertTrue(); globalSignBlob = finalOutput; console.log("signOutput: " + uInt8ArrayToShowStr(globalSignBlob.data)); - return initVerify(verifyGenerator, globalPubKey); + return initVerify(verifyGenerator, globalRsaKeyPair.pubKey); }) .then((initData) => { expect(initData === "init success").assertTrue(); @@ -672,8 +656,7 @@ async function signAndVerifyNormalProcessSuperdata(asyAlgoName, signVerifyAlgoNa async function encryptAndDecryptNormalProcessNull(asyAlgoName, cipherAlgoName) { var globalCipherText; - var globalPubKey; - var globalPriKey; + var globalRsaKeyPair; var encryptMode = cryptoFramework.CryptoMode.ENCRYPT_MODE; var decryptMode = cryptoFramework.CryptoMode.DECRYPT_MODE; @@ -688,12 +671,11 @@ async function encryptAndDecryptNormalProcessNull(asyAlgoName, cipherAlgoName) { generateAsyKeyPair(rsaGenerator) .then((rsaKeyPair) => { expect(rsaKeyPair != null).assertTrue(); - globalPubKey = rsaKeyPair.pubKey; - globalPriKey = rsaKeyPair.priKey; + globalRsaKeyPair = rsaKeyPair; return initCipher( cipherGeneratorEncrypt, encryptMode, - globalPubKey, + globalRsaKeyPair.pubKey, null ); }) @@ -710,7 +692,7 @@ async function encryptAndDecryptNormalProcessNull(asyAlgoName, cipherAlgoName) { return initCipher( cipherGeneratorDecrypt, decryptMode, - globalPriKey, + globalRsaKeyPair.priKey, null ); }) diff --git a/security/cryptoFramework/js_api_test_one/src/main/js/test/utils/asymmetric/publicAsymmetricPromise.js b/security/cryptoFramework/js_api_test_one/src/main/js/test/utils/asymmetric/publicAsymmetricPromise.js index 49ade96de..f042580fe 100644 --- a/security/cryptoFramework/js_api_test_one/src/main/js/test/utils/asymmetric/publicAsymmetricPromise.js +++ b/security/cryptoFramework/js_api_test_one/src/main/js/test/utils/asymmetric/publicAsymmetricPromise.js @@ -222,8 +222,7 @@ async function generateAsySecret(generator, priKey, pubKey) { async function encryptAndDecryptNormalProcess(asyAlgoName, cipherAlgoName) { var globalCipherText; - var globalPubKey; - var globalPriKey; + var globalRsaKeyPair; var globalText = "This is a cipher test"; var input = { data: stringTouInt8Array(globalText) }; var encryptMode = cryptoFramework.CryptoMode.ENCRYPT_MODE; @@ -240,12 +239,11 @@ async function encryptAndDecryptNormalProcess(asyAlgoName, cipherAlgoName) { generateAsyKeyPair(rsaGenerator) .then((rsaKeyPair) => { expect(rsaKeyPair != null).assertTrue(); - globalPubKey = rsaKeyPair.pubKey; - globalPriKey = rsaKeyPair.priKey; + globalRsaKeyPair = rsaKeyPair; return initCipher( cipherGeneratorEncrypt, encryptMode, - globalPubKey, + globalRsaKeyPair.pubKey, null ); }) @@ -262,7 +260,7 @@ async function encryptAndDecryptNormalProcess(asyAlgoName, cipherAlgoName) { return initCipher( cipherGeneratorDecrypt, decryptMode, - globalPriKey, + globalRsaKeyPair.priKey, null ); }) @@ -297,8 +295,7 @@ async function encryptAndDecryptNormalProcess(asyAlgoName, cipherAlgoName) { } async function signAndVerifyNormalProcess(asyAlgoName, signVerifyAlgoName) { - var globalPubKey; - var globalPriKey; + var globalRsaKeyPair; var globalSignBlob; var globalText = "This is a sign test"; var input = { data: stringTouInt8Array(globalText) }; @@ -314,9 +311,8 @@ async function signAndVerifyNormalProcess(asyAlgoName, signVerifyAlgoName) { generateAsyKeyPair(rsaGenerator) .then((rsaKeyPair) => { expect(rsaKeyPair != null).assertTrue(); - globalPubKey = rsaKeyPair.pubKey; - globalPriKey = rsaKeyPair.priKey; - return initSign(signGenerator, globalPriKey); + globalRsaKeyPair = rsaKeyPair; + return initSign(signGenerator, globalRsaKeyPair.priKey); }) .then((initData) => { expect(initData === "init success").assertTrue(); @@ -330,7 +326,7 @@ async function signAndVerifyNormalProcess(asyAlgoName, signVerifyAlgoName) { expect(finalOutput != null).assertTrue(); globalSignBlob = finalOutput; console.log("signOutput: " + uInt8ArrayToShowStr(globalSignBlob.data)); - return initVerify(verifyGenerator, globalPubKey); + return initVerify(verifyGenerator, globalRsaKeyPair.pubKey); }) .then((initData) => { expect(initData === "init success").assertTrue(); @@ -352,8 +348,7 @@ async function signAndVerifyNormalProcess(asyAlgoName, signVerifyAlgoName) { } async function signAndVerifyNormalProcessDataException(asyAlgoName, signVerifyAlgoName, dataType) { - var globalPubKey; - var globalPriKey; + var globalRsaKeyPair; var globalSignBlob; var globalText = "This is a sign test"; var input; @@ -374,9 +369,8 @@ async function signAndVerifyNormalProcessDataException(asyAlgoName, signVerifyAl generateAsyKeyPair(rsaGenerator) .then((rsaKeyPair) => { expect(rsaKeyPair != null).assertTrue(); - globalPubKey = rsaKeyPair.pubKey; - globalPriKey = rsaKeyPair.priKey; - return initSign(signGenerator, globalPriKey); + globalRsaKeyPair = rsaKeyPair; + return initSign(signGenerator, globalRsaKeyPair.priKey); }) .then((initData) => { expect(initData === "init success").assertTrue(); @@ -390,7 +384,7 @@ async function signAndVerifyNormalProcessDataException(asyAlgoName, signVerifyAl expect(finalOutput != null).assertTrue(); globalSignBlob = finalOutput; console.log("signOutput: " + uInt8ArrayToShowStr(globalSignBlob.data)); - return initVerify(verifyGenerator, globalPubKey); + return initVerify(verifyGenerator, globalRsaKeyPair.pubKey); }) .then((initData) => { expect(initData === "init success").assertTrue(); @@ -465,8 +459,7 @@ async function convertKeyEncryptAndDecryptProcess(asyAlgoName) { } async function keyAgreementProcess(ECDHAlgoName) { - var globalPubKey; - var globalPriKey; + var globalRsaKeyPair; return new Promise((resolve, reject) => { var rsaGenerator = createAsyKeyGenerator(ECDHAlgoName); @@ -477,9 +470,8 @@ async function keyAgreementProcess(ECDHAlgoName) { generateAsyKeyPair(rsaGenerator) .then((rsaKeyPair) => { expect(rsaKeyPair != null).assertTrue(); - globalPubKey = rsaKeyPair.pubKey; - globalPriKey = rsaKeyPair.priKey; - return generateAsySecret(globalECDHData, globalPriKey, globalPubKey); + globalRsaKeyPair = rsaKeyPair; + return generateAsySecret(globalECDHData, globalRsaKeyPair.priKey, globalRsaKeyPair.pubKey); }) .then((result) => { console.warn("result data is " + uInt8ArrayToShowStr(result.data)); -- GitLab