if(error){// If the service logic fails to be executed, the first parameter of callback returns error information, that is, an exception is thrown asynchronously.
// Construct the EccCommonSpec struct based on the key specifications. The EccCommonSpec struct defines the common parameters of the ECC private key and public key.
@@ -498,7 +499,7 @@ function compareRsaPubKeyBySpec(rsaKeySpec, n, e) {
returntrue;
}
// 测试根据RSA公钥密钥参数生成RSA公钥,并获得其密钥参数属性,与预期值做比较
// Generate an RSA public key based on the RSA public key specifications, obtain the key specifications, and compare the key specifications with the expected values.
// In GCM mode, the encrypted authentication information needs to be obtained from the output of doFinal() and passed in globalGcmParams of init() in decryption.
globalGcmParams.authTag=tag;
return;
})
.then(()=>{
// Initialize the Cipher instance and start decryption.
letupdateOutput=awaitglobalCipher.update(messageBlob);// Update by segment.
// Combine the result of each update() to obtain the ciphertext. In certain cases, the doFinal() results need to be combined, which depends on the cipher block mode
// and padding mode you use. In this example, the doFinal() result in GCM mode contains authTag but not ciphertext. Therefore, there is no need to combine the results.
// In GCM mode, the encrypted authentication information needs to be obtained from the output of doFinal() and passed in globalGcmParams of init() in decryption.
globalGcmParams.authTag=tag;
return;
})
.then(()=>{
// 初始化加解密操作环境:开始解密
// Initialize the Cipher instance and start decryption.
"This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!"+
"This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!"+
"This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!"+
"This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!"+
"This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!"+
"This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!"+
"This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!";
letglobalKeyPair:cryptoFramework.KeyPair;
letplainTextSplitLen=64;// The length of the plaintext to be encrypted or decrypted each time by RSA depends on the number of key bits and padding mode. For details, see the Crypto Framework Overview.
letcipherTextSplitLen=128;// Length of the ciphertext = Number of key bits/8
// Split the plaintext by 64 characters and cyclically call doFinal() to encrypt the plaintext. If a 1024-bit key is used, 128-byte ciphertext is generated each time.
// The get() and set() operations can be performed before the init() operation of the Cipher object and are equivalent to those after the init() operation. For example, set and get the decoder.
letsigner=cryptoFramework.createSign("RSA1024|PKCS1|SHA256");// API version 10开始,支持"RSA|PKCS1|SHA256"
letsigner=cryptoFramework.createSign("RSA1024|PKCS1|SHA256");// From API version 10, a Sign instance can be created by specifying a string parameter defining the key specifications.
letkeyGenPromise=rsaGenerator.generateKeyPair();
keyGenPromise.then(keyPair=>{
globalKeyPair=keyPair;
...
...
@@ -1654,7 +1607,7 @@ function signMessagePromise() {
letsigner=cryptoFramework.createSign("RSA1024|PKCS1|SHA256");// From API version 10, a Sign instance can be created by specifying a string parameter defining the key specifications.
rsaGenerator.generateKeyPair((err,keyPair)=>{
globalKeyPair=keyPair;
letpriKey=globalKeyPair.priKey;
signer.init(priKey,err=>{
...
...
@@ -1684,12 +1637,12 @@ function signMessageCallback() {