Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Xts Acts
提交
dd14b5d7
X
Xts Acts
项目概览
OpenHarmony
/
Xts Acts
1 年多 前同步成功
通知
9
Star
22
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
X
Xts Acts
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
dd14b5d7
编写于
11月 22, 2022
作者:
O
openharmony_ci
提交者:
Gitee
11月 22, 2022
浏览文件
操作
浏览文件
下载
差异文件
!6616 【OpenHarmony 3.2.9.1】【安全子系统】新增非对称加解密用例
Merge pull request !6616 from qiaozzzh/1121_1
上级
7a112fc9
62e249d4
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
1773 addition
and
142 deletion
+1773
-142
security/cryptoFramework/js_api_test_one/Test.json
security/cryptoFramework/js_api_test_one/Test.json
+1
-0
security/cryptoFramework/js_api_test_one/src/main/js/test/AsymmetricCryptography.test.js
..._test_one/src/main/js/test/AsymmetricCryptography.test.js
+1300
-142
security/cryptoFramework/js_api_test_one/src/main/js/test/utils/asymmetric/publicAsymmetricCallback.js
...main/js/test/utils/asymmetric/publicAsymmetricCallback.js
+330
-0
security/cryptoFramework/js_api_test_one/src/main/js/test/utils/asymmetric/publicAsymmetricPromise.js
.../main/js/test/utils/asymmetric/publicAsymmetricPromise.js
+142
-0
未找到文件。
security/cryptoFramework/js_api_test_one/Test.json
浏览文件 @
dd14b5d7
...
...
@@ -4,6 +4,7 @@
"type"
:
"OHJSUnitTest"
,
"test-timeout"
:
"900000"
,
"shell-timeout"
:
"900000"
,
"testcase-timeout"
:
"180000"
,
"bundle-name"
:
"com.openharmony.cryptoFramework1"
,
"package-name"
:
"com.openharmony.cryptoFramework1"
},
...
...
security/cryptoFramework/js_api_test_one/src/main/js/test/AsymmetricCryptography.test.js
浏览文件 @
dd14b5d7
...
...
@@ -79,23 +79,891 @@ export default function AsymmetricCryptographyJsunit() {
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_Encryption_RSA_0300
* @tc.name Test RSA3072 normal encryption and decryption
* @tc.desc Use the Callback Style of Interface
*/
it
(
"
Security_crypto_framework_ASymmetric_Encryption_RSA_0300
"
,
0
,
async
function
(
done
)
{
await
asyCallback
.
encryptAndDecryptNormalProcess
(
"
RSA3072
"
,
"
RSA3072|PKCS1|SHA224
"
)
.
then
((
data
)
=>
{
expect
(
data
==
null
).
assertTrue
();
})
.
catch
((
err
)
=>
{
console
.
error
(
"
Security_crypto_framework_ASymmetric_Encryption_RSA_0300 catch error:
"
+
err
);
expect
(
null
).
assertFail
();
});
done
();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_Encryption_RSA_0400
* @tc.name Test RSA4096 normal encryption and decryption
* @tc.desc Use the Promise Style of Interface
*/
it
(
"
Security_crypto_framework_ASymmetric_Encryption_RSA_0400
"
,
0
,
async
function
(
done
)
{
await
asyPromise
.
encryptAndDecryptNormalProcess
(
"
RSA4096
"
,
"
RSA4096|PKCS1_OAEP|MD5|MGF1_SHA512
"
)
.
then
((
data
)
=>
{
expect
(
data
==
null
).
assertTrue
();
})
.
catch
((
err
)
=>
{
console
.
error
(
"
Security_crypto_framework_ASymmetric_Encryption_RSA_0400 catch error:
"
+
err
);
expect
(
null
).
assertFail
();
});
done
();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_Encryption_RSA_0500
* @tc.name Test RSA3072 normal encryption and decryption
* @tc.desc Use the Callback Style of Interface
*/
it
(
"
Security_crypto_framework_ASymmetric_Encryption_RSA_0500
"
,
0
,
async
function
(
done
)
{
await
asyCallback
.
encryptAndDecryptNormalProcess
(
"
RSA8192
"
,
"
RSA8192|PKCS1_OAEP|SHA1|MGF1_SHA384
"
)
.
then
((
data
)
=>
{
expect
(
data
==
null
).
assertTrue
();
})
.
catch
((
err
)
=>
{
console
.
error
(
"
Security_crypto_framework_ASymmetric_Encryption_RSA_0500 catch error:
"
+
err
);
expect
(
null
).
assertFail
();
});
done
();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_Encryption_RSA_0600
* @tc.name Test RSA3072|PKCS1|SHA256 normal encryption and decryption
* @tc.desc Use the Promise Style of Interface
*/
it
(
"
Security_crypto_framework_ASymmetric_Encryption_RSA_0600
"
,
0
,
async
function
(
done
)
{
await
asyPromise
.
encryptAndDecryptNormalProcess
(
"
RSA3072|PRIMES_3
"
,
"
RSA3072|PKCS1|SHA256
"
)
.
then
((
data
)
=>
{
expect
(
data
==
null
).
assertTrue
();
})
.
catch
((
err
)
=>
{
console
.
error
(
"
Security_crypto_framework_ASymmetric_Encryption_RSA_0600 catch error:
"
+
err
);
expect
(
null
).
assertFail
();
});
done
();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_Encryption_RSA_0700
* @tc.name Test RSA3072|PKCS1|SHA512 normal encryption and decryption
* @tc.desc Use the Callback Style of Interface
*/
it
(
"
Security_crypto_framework_ASymmetric_Encryption_RSA_0700
"
,
0
,
async
function
(
done
)
{
await
asyCallback
.
encryptAndDecryptNormalProcess
(
"
RSA3072
"
,
"
RSA3072|PKCS1|SHA512
"
)
.
then
((
data
)
=>
{
expect
(
data
==
null
).
assertTrue
();
})
.
catch
((
err
)
=>
{
console
.
error
(
"
Security_crypto_framework_ASymmetric_Encryption_RSA_0700 catch error:
"
+
err
);
expect
(
null
).
assertFail
();
});
done
();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_Encryption_RSA_0800
* @tc.name Test RSA3072|PKCS1_OAEP|SHA224|MGF1_SHA256 normal encryption and decryption
* @tc.desc Use the Promise Style of Interface
*/
it
(
"
Security_crypto_framework_ASymmetric_Encryption_RSA_0800
"
,
0
,
async
function
(
done
)
{
await
asyPromise
.
encryptAndDecryptNormalProcess
(
"
RSA3072
"
,
"
RSA3072|PKCS1_OAEP|SHA224|MGF1_SHA256
"
)
.
then
((
data
)
=>
{
expect
(
data
==
null
).
assertTrue
();
})
.
catch
((
err
)
=>
{
console
.
error
(
"
Security_crypto_framework_ASymmetric_Encryption_RSA_0800 catch error:
"
+
err
);
expect
(
null
).
assertFail
();
});
done
();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_Encryption_RSA_0900
* @tc.name Test RSA512|PKCS1_OAEP|SHA256|MGF1_SHA224 normal encryption and decryption
* @tc.desc Use the Callback Style of Interface
*/
it
(
"
Security_crypto_framework_ASymmetric_Encryption_RSA_0900
"
,
0
,
async
function
(
done
)
{
await
asyCallback
.
encryptAndDecryptNormalProcess
(
"
RSA1024
"
,
"
RSA1024|PKCS1_OAEP|SHA256|MGF1_SHA224
"
)
.
then
((
data
)
=>
{
expect
(
data
==
null
).
assertTrue
();
})
.
catch
((
err
)
=>
{
console
.
error
(
"
Security_crypto_framework_ASymmetric_Encryption_RSA_0900 catch error:
"
+
err
);
expect
(
null
).
assertFail
();
});
done
();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_Encryption_RSA_1000
* @tc.name Test RSA3072|PKCS1_OAEP|SHA384|MGF1_SHA1 normal encryption and decryption
* @tc.desc Use the Promise Style of Interface
*/
it
(
"
Security_crypto_framework_ASymmetric_Encryption_RSA_1000
"
,
0
,
async
function
(
done
)
{
await
asyPromise
.
encryptAndDecryptNormalProcess
(
"
RSA3072|PRIMES_3
"
,
"
RSA3072|PKCS1_OAEP|SHA384|MGF1_SHA1
"
)
.
then
((
data
)
=>
{
expect
(
data
==
null
).
assertTrue
();
})
.
catch
((
err
)
=>
{
console
.
error
(
"
Security_crypto_framework_ASymmetric_Encryption_RSA_1000 catch error:
"
+
err
);
expect
(
null
).
assertFail
();
});
done
();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_Encryption_RSA_1100
* @tc.name Test RSA3072|PKCS1_OAEP|SHA512|MGF1_MD5 normal encryption and decryption
* @tc.desc Use the Callback Style of Interface
*/
it
(
"
Security_crypto_framework_ASymmetric_Encryption_RSA_1100
"
,
0
,
async
function
(
done
)
{
await
asyCallback
.
encryptAndDecryptNormalProcess
(
"
RSA3072
"
,
"
RSA3072|PKCS1_OAEP|SHA512|MGF1_MD5
"
)
.
then
((
data
)
=>
{
expect
(
data
==
null
).
assertTrue
();
})
.
catch
((
err
)
=>
{
console
.
error
(
"
Security_crypto_framework_ASymmetric_Encryption_RSA_1100 catch error:
"
+
err
);
expect
(
null
).
assertFail
();
});
done
();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_Encryption_RSA_1200
* @tc.name Test RSA3072|PKCS1 normal encryption and decryption
* @tc.desc Use the Promise Style of Interface
*/
it
(
"
Security_crypto_framework_ASymmetric_Encryption_RSA_1200
"
,
0
,
async
function
(
done
)
{
await
asyPromise
.
encryptAndDecryptNormalProcess
(
"
RSA3072
"
,
"
RSA3072|PKCS1
"
)
.
then
((
data
)
=>
{
expect
(
data
==
null
).
assertTrue
();
})
.
catch
((
err
)
=>
{
console
.
error
(
"
Security_crypto_framework_ASymmetric_Encryption_RSA_1200 catch error:
"
+
err
);
expect
(
null
).
assertFail
();
});
done
();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_Encryption_RSA_1300
* @tc.name Test RSA4096|PKCS1 normal encryption and decryption
* @tc.desc Use the Callback Style of Interface
*/
it
(
"
Security_crypto_framework_ASymmetric_Encryption_RSA_1300
"
,
0
,
async
function
(
done
)
{
await
asyCallback
.
encryptAndDecryptNormalProcess
(
"
RSA4096
"
,
"
RSA4096|PKCS1
"
)
.
then
((
data
)
=>
{
expect
(
data
==
null
).
assertTrue
();
})
.
catch
((
err
)
=>
{
console
.
error
(
"
Security_crypto_framework_ASymmetric_Encryption_RSA_1300 catch error:
"
+
err
);
expect
(
null
).
assertFail
();
});
done
();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_Encryption_RSA_1400
* @tc.name Test RSA4096|PKCS1 normal encryption and decryption
* @tc.desc Use the Callback Style of Interface
*/
it
(
"
Security_crypto_framework_ASymmetric_Encryption_RSA_1400
"
,
0
,
async
function
(
done
)
{
await
asyCallback
.
encryptAndDecryptNormalProcessNull
(
"
RSA4096
"
,
"
RSA4096|PKCS1
"
)
.
then
((
data
)
=>
{
expect
(
data
==
"
Error: doFinal failed.
"
).
assertTrue
();
})
.
catch
((
err
)
=>
{
console
.
error
(
"
Security_crypto_framework_ASymmetric_Encryption_RSA_1400 catch error:
"
+
err
);
expect
(
null
).
assertFail
();
});
done
();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_0100
* @tc.name Test RSA1024|PKCS1|MD5 normal sign and verify
* @tc.desc Use the Callback Style of Interface
*/
it
(
"
Security_crypto_framework_ASymmetric_SignVerify_RSA_0100
"
,
"
Security_crypto_framework_ASymmetric_SignVerify_RSA_0100
"
,
0
,
async
function
(
done
)
{
await
asyCallback
.
signAndVerifyNormalProcess
(
"
RSA1024|PRIMES_2
"
,
"
RSA1024|PKCS1|MD5
"
)
.
then
((
data
)
=>
{
expect
(
data
==
null
).
assertTrue
();
})
.
catch
((
err
)
=>
{
console
.
error
(
"
Security_crypto_framework_ASymmetric_SignVerify_RSA_0100 catch error:
"
+
err
);
expect
(
null
).
assertFail
();
});
done
();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_0200
* @tc.name Test RSA2048|PKCS1|SHA1 normal sign and verify
* @tc.desc Use the Promise Style of Interface
*/
it
(
"
Security_crypto_framework_ASymmetric_SignVerify_RSA_0200
"
,
0
,
async
function
(
done
)
{
await
asyPromise
.
signAndVerifyNormalProcess
(
"
RSA2048|PRIMES_2
"
,
"
RSA2048|PKCS1|SHA1
"
)
.
then
((
data
)
=>
{
expect
(
data
==
null
).
assertTrue
();
})
.
catch
((
err
)
=>
{
console
.
error
(
"
Security_crypto_framework_ASymmetric_SignVerify_RSA_0200 catch error:
"
+
err
);
expect
(
null
).
assertFail
();
});
done
();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_0300
* @tc.name Test RSA3072|PKCS1|SHA224 normal sign and verify
* @tc.desc Use the Callback Style of Interface
*/
it
(
"
Security_crypto_framework_ASymmetric_SignVerify_RSA_0300
"
,
0
,
async
function
(
done
)
{
await
asyCallback
.
signAndVerifyNormalProcess
(
"
RSA3072|PRIMES_2
"
,
"
RSA3072|PKCS1|SHA224
"
)
.
then
((
data
)
=>
{
expect
(
data
==
null
).
assertTrue
();
})
.
catch
((
err
)
=>
{
console
.
error
(
"
Security_crypto_framework_ASymmetric_SignVerify_RSA_0300 catch error:
"
+
err
);
expect
(
null
).
assertFail
();
});
done
();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_0400
* @tc.name Test RSA2048|PKCS1|SHA1 normal sign and verify
* @tc.desc Use the Promise Style of Interface
*/
it
(
"
Security_crypto_framework_ASymmetric_SignVerify_RSA_0400
"
,
0
,
async
function
(
done
)
{
await
asyPromise
.
signAndVerifyNormalProcess
(
"
RSA4096|PRIMES_2
"
,
"
RSA4096|PKCS1|SHA256
"
)
.
then
((
data
)
=>
{
expect
(
data
==
null
).
assertTrue
();
})
.
catch
((
err
)
=>
{
console
.
error
(
"
Security_crypto_framework_ASymmetric_SignVerify_RSA_0400 catch error:
"
+
err
);
expect
(
null
).
assertFail
();
});
done
();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_0500
* @tc.name Test RSA8192|PKCS1|SHA384 normal sign and verify
* @tc.desc Use the Promise Style of Interface
*/
it
(
"
Security_crypto_framework_ASymmetric_SignVerify_RSA_0500
"
,
0
,
async
function
(
done
)
{
await
asyPromise
.
signAndVerifyNormalProcess
(
"
RSA8192|PRIMES_3
"
,
"
RSA8192|PKCS1|SHA384
"
)
.
then
((
data
)
=>
{
expect
(
data
==
null
).
assertTrue
();
})
.
catch
((
err
)
=>
{
console
.
error
(
"
Security_crypto_framework_ASymmetric_SignVerify_RSA_0500 catch error:
"
+
err
);
expect
(
null
).
assertFail
();
});
done
();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_0600
* @tc.name Test RSA512|PKCS1|SHA512 normal sign and verify
* @tc.desc Use the Promise Style of Interface
*/
it
(
"
Security_crypto_framework_ASymmetric_SignVerify_RSA_0600
"
,
0
,
async
function
(
done
)
{
await
asyPromise
.
signAndVerifyNormalProcess
(
"
RSA512|PRIMES_2
"
,
"
RSA512|PKCS1|SHA256
"
)
.
then
((
data
)
=>
{
expect
(
data
==
null
).
assertTrue
();
})
.
catch
((
err
)
=>
{
console
.
error
(
"
Security_crypto_framework_ASymmetric_SignVerify_RSA_0600 catch error:
"
+
err
);
expect
(
null
).
assertFail
();
});
done
();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_0700
* @tc.name Test RSA1024|PKCS1|MD5|MGF1_MD5 normal sign and verify
* @tc.desc Use the Callback Style of Interface
*/
it
(
"
Security_crypto_framework_ASymmetric_SignVerify_RSA_0700
"
,
0
,
async
function
(
done
)
{
await
asyCallback
.
signAndVerifyNormalProcess
(
"
RSA1024
"
,
"
RSA1024|PKCS1|MD5|MGF1_MD5
"
)
.
then
((
data
)
=>
{
expect
(
data
==
null
).
assertTrue
();
})
.
catch
((
err
)
=>
{
console
.
error
(
"
Security_crypto_framework_ASymmetric_SignVerify_RSA_0700 catch error:
"
+
err
);
expect
(
null
).
assertFail
();
});
done
();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_0800
* @tc.name Test RSA2048|PSS|SHA1|MGF1_SHA1 normal sign and verify
* @tc.desc Use the Promise Style of Interface
*/
it
(
"
Security_crypto_framework_ASymmetric_SignVerify_RSA_0800
"
,
0
,
async
function
(
done
)
{
await
asyPromise
.
signAndVerifyNormalProcess
(
"
RSA2048
"
,
"
RSA2048|PSS|SHA1|MGF1_SHA1
"
)
.
then
((
data
)
=>
{
expect
(
data
==
null
).
assertTrue
();
})
.
catch
((
err
)
=>
{
console
.
error
(
"
Security_crypto_framework_ASymmetric_SignVerify_RSA_0800 catch error:
"
+
err
);
expect
(
null
).
assertFail
();
});
done
();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_0900
* @tc.name Test RSA3072|PSS|SHA224|MGF1_SHA224 normal sign and verify
* @tc.desc Use the Callback Style of Interface
*/
it
(
"
Security_crypto_framework_ASymmetric_SignVerify_RSA_0900
"
,
0
,
async
function
(
done
)
{
await
asyCallback
.
signAndVerifyNormalProcess
(
"
RSA3072
"
,
"
RSA3072|PSS|SHA224|MGF1_SHA224
"
)
.
then
((
data
)
=>
{
expect
(
data
==
null
).
assertTrue
();
})
.
catch
((
err
)
=>
{
console
.
error
(
"
Security_crypto_framework_ASymmetric_SignVerify_RSA_0900 catch error:
"
+
err
);
expect
(
null
).
assertFail
();
});
done
();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_1000
* @tc.name Test RSA4096|PSS|SHA256|MGF1_SHA256 normal sign and verify
* @tc.desc Use the Callback Style of Interface
*/
it
(
"
Security_crypto_framework_ASymmetric_SignVerify_RSA_1000
"
,
0
,
async
function
(
done
)
{
await
asyCallback
.
signAndVerifyNormalProcess
(
"
RSA4096
"
,
"
RSA4096|PSS|SHA256|MGF1_SHA256
"
)
.
then
((
data
)
=>
{
expect
(
data
==
null
).
assertTrue
();
})
.
catch
((
err
)
=>
{
console
.
error
(
"
Security_crypto_framework_ASymmetric_SignVerify_RSA_1000 catch error:
"
+
err
);
expect
(
null
).
assertFail
();
});
done
();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_1100
* @tc.name Test RSA2048|PSS|SHA1|MGF1_SHA1 normal sign and verify
* @tc.desc Use the Promise Style of Interface
*/
it
(
"
Security_crypto_framework_ASymmetric_SignVerify_RSA_1100
"
,
0
,
async
function
(
done
)
{
await
asyPromise
.
signAndVerifyNormalProcess
(
"
RSA8192
"
,
"
RSA8192|PSS|SHA512|MGF1_SHA512
"
)
.
then
((
data
)
=>
{
expect
(
data
==
null
).
assertTrue
();
})
.
catch
((
err
)
=>
{
console
.
error
(
"
Security_crypto_framework_ASymmetric_SignVerify_RSA_1100 catch error:
"
+
err
);
expect
(
null
).
assertFail
();
});
done
();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_1200
* @tc.name Test RSA2048|PSS|SHA1|MGF1_SHA1 normal sign and verify
* @tc.desc Use the Promise Style of Interface
*/
it
(
"
Security_crypto_framework_ASymmetric_SignVerify_RSA_1200
"
,
0
,
async
function
(
done
)
{
await
asyPromise
.
signAndVerifyNormalProcess
(
"
RSA512
"
,
"
RSA512|PSS|SHA384|MGF1_SHA384
"
)
.
then
((
data
)
=>
{
expect
(
data
==
null
).
assertTrue
();
})
.
catch
((
err
)
=>
{
console
.
error
(
"
Security_crypto_framework_ASymmetric_SignVerify_RSA_1200 catch error:
"
+
err
);
expect
(
null
).
assertFail
();
});
done
();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_5000
* @tc.name Test RSA2048|PSS|SHA1|MGF1_SHA1 normal sign and verify
* @tc.desc Use the Promise Style of Interface
*/
it
(
"
Security_crypto_framework_ASymmetric_SignVerify_RSA_5000
"
,
0
,
async
function
(
done
)
{
await
asyPromise
.
signAndVerifyNormalProcessDataException
(
"
RSA512
"
,
"
RSA512|PSS|SHA384|MGF1_SHA384
"
,
"
null
"
)
.
then
((
data
)
=>
{
expect
(
data
==
"
Error: [Data]: must be of the DataBlob type.
"
).
assertTrue
();
})
.
catch
((
err
)
=>
{
console
.
error
(
"
Security_crypto_framework_ASymmetric_SignVerify_RSA_5000 catch error:
"
+
err
);
expect
(
null
).
assertFail
();
});
done
();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_1300
* @tc.name Test RSA256 or null normal sign and verify
* @tc.desc Use the Promise Style of Interface
*/
it
(
"
Security_crypto_framework_ASymmetric_SignVerify_RSA_1300
"
,
0
,
async
function
(
done
)
{
await
asyPromise
.
createAsyKeyGeneratorFail
(
"
RSA256
"
)
.
then
((
data
)
=>
{
expect
(
data
==
"
TypeError: Cannot read property algName of null
"
).
assertTrue
();
})
.
catch
((
err
)
=>
{
console
.
error
(
"
Security_crypto_framework_ASymmetric_SignVerify_RSA_1300 catch error:
"
+
err
);
expect
(
null
).
assertFail
();
});
await
asyPromise
.
createAsyKeyGeneratorFail
(
"
null
"
)
.
then
((
data
)
=>
{
expect
(
data
==
"
TypeError: Cannot read property algName of null
"
).
assertTrue
();
})
.
catch
((
err
)
=>
{
console
.
error
(
"
Security_crypto_framework_ASymmetric_SignVerify_RSA_1300 catch error:
"
+
err
);
expect
(
null
).
assertFail
();
});
done
();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_1400
* @tc.name Test RSA2048|PSS|SHA1|MGF1_SHA1 normal sign and verify
* @tc.desc Use the Promise Style of Interface
*/
it
(
"
Security_crypto_framework_ASymmetric_SignVerify_RSA_1400
"
,
0
,
async
function
(
done
)
{
await
asyPromise
.
createAsySignFail
(
"
RSA3072
"
,
"
RSA4096|null|SHA256
"
,
"
RSA4096|PKCS1|null
"
,
"
RSA4096|PKCS1|SHA122
"
,
"
RSA4096|PKCS3|SHA256
"
)
.
then
((
data
)
=>
{
expect
(
data
==
"
TypeError: Cannot read property algName of undefined
"
).
assertTrue
();
})
.
catch
((
err
)
=>
{
console
.
error
(
"
Security_crypto_framework_ASymmetric_SignVerify_RSA_1400 catch error:
"
+
err
);
expect
(
null
).
assertFail
();
});
done
();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_Encryption_RSA_2000
* @tc.name Test RSA4096|PKCS1 normal encryption and decryption
* @tc.desc Use the Callback Style of Interface
*/
it
(
"
Security_crypto_framework_ASymmetric_Encryption_RSA_2000
"
,
0
,
async
function
(
done
)
{
await
asyCallback
.
encryptAndDecryptNormalProcessSuperdata
(
"
RSA4096
"
,
"
RSA4096|PKCS1
"
,
"
490
"
)
.
then
((
data
)
=>
{
expect
(
data
==
null
).
assertTrue
();
})
.
catch
((
err
)
=>
{
console
.
error
(
"
Security_crypto_framework_ASymmetric_Encryption_RSA_2000 catch error:
"
+
err
);
expect
(
null
).
assertFail
();
});
done
();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_2100
* @tc.name Test RSA3072|PKCS1|SHA224 normal sign and verify
* @tc.desc Use the Callback Style of Interface
*/
it
(
"
Security_crypto_framework_ASymmetric_SignVerify_RSA_2100
"
,
0
,
async
function
(
done
)
{
await
asyCallback
.
signAndVerifyNormalProcessSuperdata
(
"
RSA3072
"
,
"
RSA3072|PKCS1|SHA224
"
,
"
350
"
)
.
then
((
data
)
=>
{
expect
(
data
==
null
).
assertTrue
();
})
.
catch
((
err
)
=>
{
console
.
error
(
"
Security_crypto_framework_ASymmetric_SignVerify_RSA_2100 catch error:
"
+
err
);
expect
(
null
).
assertFail
();
});
done
();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_1500
* @tc.name Test RSA2048|PSS|SHA1|MGF1_SHA1 normal sign and verify
* @tc.desc Use the Promise Style of Interface
*/
it
(
"
Security_crypto_framework_ASymmetric_SignVerify_RSA_1500
"
,
0
,
async
function
(
done
)
{
await
asyPromise
.
createAsyVerifyFail
(
"
RSA3072
"
,
"
RSA4096|null|SHA256
"
,
"
RSA4096|PKCS1|null
"
,
"
RSA4096|PKCS1|SHA122
"
,
"
RSA4096|PKCS3|SHA256
"
)
.
then
((
data
)
=>
{
expect
(
data
==
"
TypeError: Cannot read property algName of undefined
"
).
assertTrue
();
})
.
catch
((
err
)
=>
{
console
.
error
(
"
Security_crypto_framework_ASymmetric_SignVerify_RSA_1500 catch error:
"
+
err
);
expect
(
null
).
assertFail
();
});
done
();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0100
* @tc.name Test ECC224|SHA256 normal sign and verify
* @tc.desc Use the Callback Style of Interface
*/
it
(
"
Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0100
"
,
0
,
async
function
(
done
)
{
await
asyCallback
.
signAndVerifyNormalProcess
(
"
ECC224
"
,
"
ECC224|SHA256
"
)
.
then
((
data
)
=>
{
expect
(
data
==
null
).
assertTrue
();
})
.
catch
((
err
)
=>
{
console
.
error
(
"
Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0100 catch error:
"
+
err
);
expect
(
null
).
assertFail
();
});
done
();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0200
* @tc.name Test ECC256|SHA1 normal sign and verify
* @tc.desc Use the Promise Style of Interface
*/
it
(
"
Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0200
"
,
0
,
async
function
(
done
)
{
await
asyPromise
.
signAndVerifyNormalProcess
(
"
ECC256
"
,
"
ECC256|SHA1
"
)
.
then
((
data
)
=>
{
expect
(
data
==
null
).
assertTrue
();
})
.
catch
((
err
)
=>
{
console
.
error
(
"
Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0200 catch error:
"
+
err
);
expect
(
null
).
assertFail
();
});
done
();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0300
* @tc.name Test ECC224|SHA256 normal sign and verify
* @tc.desc Use the Callback Style of Interface
*/
it
(
"
Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0300
"
,
0
,
async
function
(
done
)
{
await
asyCallback
.
signAndVerifyNormalProcess
(
"
RSA1024|PRIMES_2
"
,
"
RSA1024|PKCS1|MD5
"
)
.
signAndVerifyNormalProcess
(
"
ECC384
"
,
"
ECC384|SHA224
"
)
.
then
((
data
)
=>
{
expect
(
data
==
null
).
assertTrue
();
})
.
catch
((
err
)
=>
{
console
.
error
(
"
Security_crypto_framework_ASymmetric_SignVerify_RSA_01
00 catch error:
"
+
"
Security_crypto_framework_ASymmetric_SignVerify_ECDSA_03
00 catch error:
"
+
err
);
expect
(
null
).
assertFail
();
...
...
@@ -105,22 +973,175 @@ export default function AsymmetricCryptographyJsunit() {
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_
RSA_02
00
* @tc.name Test
RSA2048|PKCS1|SHA1
normal sign and verify
* @tc.desc Use the
Promise
Style of Interface
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_
ECDSA_04
00
* @tc.name Test
ECC521|SHA384
normal sign and verify
* @tc.desc Use the
Callback
Style of Interface
*/
it
(
"
Security_crypto_framework_ASymmetric_SignVerify_RSA_02
00
"
,
"
Security_crypto_framework_ASymmetric_SignVerify_ECDSA_04
00
"
,
0
,
async
function
(
done
)
{
await
asyPromise
.
signAndVerifyNormalProcess
(
"
RSA2048|PRIMES_2
"
,
"
RSA2048|PKCS1|SHA1
"
)
.
signAndVerifyNormalProcess
(
"
ECC512
"
,
"
ECC512|SHA384
"
)
.
then
((
data
)
=>
{
expect
(
data
==
null
).
assertTrue
();
})
.
catch
((
err
)
=>
{
console
.
error
(
"
Security_crypto_framework_ASymmetric_SignVerify_RSA_0200 catch error:
"
+
"
Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0400 catch error:
"
+
err
);
expect
(
null
).
assertFail
();
});
done
();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0500
* @tc.name Test ECC224|SHA512 normal sign and verify
* @tc.desc Use the Callback Style of Interface
*/
it
(
"
Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0500
"
,
0
,
async
function
(
done
)
{
await
asyPromise
.
signAndVerifyNormalProcess
(
"
ECC224
"
,
"
ECC224|SHA512
"
)
.
then
((
data
)
=>
{
expect
(
data
==
null
).
assertTrue
();
})
.
catch
((
err
)
=>
{
console
.
error
(
"
Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0500 catch error:
"
+
err
);
expect
(
null
).
assertFail
();
});
done
();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0600
* @tc.name Test ECC1 or NULL normal sign and verify
* @tc.desc Use the Callback Style of Interface
*/
it
(
"
Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0600
"
,
0
,
async
function
(
done
)
{
await
asyCallback
.
createAsyKeyGeneratorFail
(
"
ECC1
"
)
.
then
((
data
)
=>
{
expect
(
data
==
"
TypeError: Cannot read property algName of null
"
).
assertTrue
();
})
.
catch
((
err
)
=>
{
console
.
error
(
"
Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0600 catch error:
"
+
err
);
expect
(
null
).
assertFail
();
});
await
asyCallback
.
createAsyKeyGeneratorFail
(
"
null
"
)
.
then
((
data
)
=>
{
expect
(
data
==
"
TypeError: Cannot read property algName of null
"
).
assertTrue
();
})
.
catch
((
err
)
=>
{
console
.
error
(
"
Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0600 catch error:
"
+
err
);
expect
(
null
).
assertFail
();
});
done
();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0700
* @tc.name Test ECC224 normal sign and verify
* @tc.desc Use the Callback Style of Interface
*/
it
(
"
Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0700
"
,
0
,
async
function
(
done
)
{
await
asyPromise
.
createAsySignFail
(
"
ECC224
"
,
"
ECC224|SHA257
"
,
"
ECC224|NULL
"
,
"
NULL|SHA1
"
,
"
ECC|SHA
"
)
.
then
((
data
)
=>
{
expect
(
data
==
"
TypeError: Cannot read property algName of undefined
"
).
assertTrue
();
})
.
catch
((
err
)
=>
{
console
.
error
(
"
Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0700:
"
+
err
);
expect
(
null
).
assertFail
();
});
done
();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0800
* @tc.name Test RSA3072 normal sign and verify
* @tc.desc Use the Callback Style of Interface
*/
it
(
"
Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0800
"
,
0
,
async
function
(
done
)
{
await
asyPromise
.
createAsyVerifyFail
(
"
ECC224
"
,
"
ECC1|SHA256
"
,
"
NULL|SHA256
"
,
"
ECC224|SHA122
"
,
"
ECC224|NULL
"
)
.
then
((
data
)
=>
{
expect
(
data
==
"
TypeError: Cannot read property algName of undefined
"
).
assertTrue
();
})
.
catch
((
err
)
=>
{
console
.
error
(
"
Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0800 catch error:
"
+
err
);
expect
(
null
).
assertFail
();
});
done
();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0900
* @tc.name Test ECC224|SHA512 normal sign and verify
* @tc.desc Use the Callback Style of Interface
*/
it
(
"
Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0900
"
,
0
,
async
function
(
done
)
{
await
asyCallback
.
signAndVerifyNormalProcessSuperdata
(
"
ECC224
"
,
"
ECC224|SHA512
"
,
"
350
"
)
.
then
((
data
)
=>
{
expect
(
data
==
null
).
assertTrue
();
})
.
catch
((
err
)
=>
{
console
.
error
(
"
Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0900 catch error:
"
+
err
);
expect
(
null
).
assertFail
();
...
...
@@ -179,6 +1200,143 @@ export default function AsymmetricCryptographyJsunit() {
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_ECDH_0300
* @tc.name Test ECC384 SignVerify ECDH
* @tc.desc Use the Promise Style of Interface
*/
it
(
"
Security_crypto_framework_ASymmetric_SignVerify_ECDH_0300
"
,
0
,
async
function
(
done
)
{
await
asyPromise
.
keyAgreementProcess
(
"
ECC384
"
)
.
then
((
data
)
=>
{
expect
(
data
==
null
).
assertTrue
();
})
.
catch
((
err
)
=>
{
console
.
error
(
"
Security_crypto_framework_ASymmetric_SignVerify_ECDH_0300 catch error:
"
+
err
);
expect
(
null
).
assertFail
();
});
done
();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_ECDH_0400
* @tc.name Test ECC512 SignVerify ECDH
* @tc.desc Use the Callback Style of Interface
*/
it
(
"
Security_crypto_framework_ASymmetric_SignVerify_ECDH_0400
"
,
0
,
async
function
(
done
)
{
await
asyCallback
.
keyAgreementProcess
(
"
ECC512
"
)
.
then
((
data
)
=>
{
expect
(
data
==
null
).
assertTrue
();
})
.
catch
((
err
)
=>
{
console
.
error
(
"
Security_crypto_framework_ASymmetric_SignVerify_ECDH_0400 catch error:
"
+
err
);
expect
(
null
).
assertFail
();
});
done
();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_ECDH_0500
* @tc.name Test ECC5 or null SignVerify ECDH
* @tc.desc Use the Callback Style of Interface
*/
it
(
"
Security_crypto_framework_ASymmetric_SignVerify_ECDH_0500
"
,
0
,
async
function
(
done
)
{
await
asyCallback
.
createAsyKeyAgreementFail
(
"
ECC5
"
)
.
then
((
data
)
=>
{
expect
(
data
==
"
TypeError: Cannot read property algName of undefined
"
).
assertTrue
();
})
.
catch
((
err
)
=>
{
console
.
error
(
"
Security_crypto_framework_ASymmetric_SignVerify_ECDH_0500 catch error:
"
+
err
);
expect
(
null
).
assertFail
();
});
await
asyCallback
.
createAsyKeyAgreementFail
(
"
null
"
)
.
then
((
data
)
=>
{
expect
(
data
==
"
TypeError: Cannot read property algName of undefined
"
).
assertTrue
();
})
.
catch
((
err
)
=>
{
console
.
error
(
"
Security_crypto_framework_ASymmetric_SignVerify_ECDH_0500 catch error:
"
+
err
);
expect
(
null
).
assertFail
();
});
done
();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_ECDH_0600
* @tc.name Test ECC256 SignVerify ECDH
* @tc.desc Use the Callback Style of Interface
*/
it
(
"
Security_crypto_framework_ASymmetric_SignVerify_ECDH_0600
"
,
0
,
async
function
(
done
)
{
await
asyCallback
.
keyAgreementProcessParameterException
(
"
ECC256
"
)
.
then
((
data
)
=>
{
expect
(
data
==
"
Error: [PriKey]: param unwarp error.
"
).
assertTrue
();
})
.
catch
((
err
)
=>
{
console
.
error
(
"
Security_crypto_framework_ASymmetric_SignVerify_ECDH_0600 catch error:
"
+
err
);
expect
(
null
).
assertFail
();
});
done
();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_ECDH_0700
* @tc.name Test RSA3072 SignVerify ECDH
* @tc.desc Use the Callback Style of Interface
*/
it
(
"
Security_crypto_framework_ASymmetric_SignVerify_ECDH_0700
"
,
0
,
async
function
(
done
)
{
await
asyCallback
.
keyAgreementProcessFail
(
"
RSA3072
"
,
"
ECC512
"
)
.
then
((
data
)
=>
{
expect
(
data
==
"
Error: An exception occurs.
"
).
assertTrue
();
})
.
catch
((
err
)
=>
{
console
.
error
(
"
Security_crypto_framework_ASymmetric_SignVerify_ECDH_0700 catch error:
"
+
err
);
expect
(
null
).
assertFail
();
});
done
();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_Encryption_RSA_3300
* @tc.name Test convertKey
...
...
security/cryptoFramework/js_api_test_one/src/main/js/test/utils/asymmetric/publicAsymmetricCallback.js
浏览文件 @
dd14b5d7
...
...
@@ -391,6 +391,17 @@ async function convertKeyEncryptAndDecryptProcess(asyAlgoName) {
});
}
async
function
createAsyKeyAgreementFail
(
ECDHAlgoName
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
var
globalECDHData
=
createAsyKeyAgreement
(
ECDHAlgoName
);
resolve
(
globalECDHData
);
expect
(
globalECDHData
==
"
TypeError: Cannot read property algName of undefined
"
).
assertTrue
();
if
(
globalECDHData
!=
"
TypeError: Cannot read property algName of undefined
"
){
reject
();
}
});
}
async
function
keyAgreementProcess
(
ECDHAlgoName
)
{
var
globalPubKey
;
var
globalPriKey
;
...
...
@@ -420,9 +431,328 @@ async function keyAgreementProcess(ECDHAlgoName) {
});
}
async
function
keyAgreementProcessFail
(
ECDHAlgoName
,
ECDHAlgoName1
)
{
var
globalPubKey
;
var
globalPriKey
;
return
new
Promise
((
resolve
,
reject
)
=>
{
var
rsaGenerator
=
createAsyKeyGenerator
(
ECDHAlgoName
);
expect
(
rsaGenerator
!=
null
).
assertTrue
();
var
globalECDHData
=
createAsyKeyAgreement
(
ECDHAlgoName1
);
expect
(
globalECDHData
!=
null
).
assertTrue
();
generateAsyKeyPair
(
rsaGenerator
)
.
then
((
rsaKeyPair
)
=>
{
expect
(
rsaKeyPair
!=
null
).
assertTrue
();
globalPubKey
=
rsaKeyPair
.
pubKey
;
globalPriKey
=
rsaKeyPair
.
priKey
;
return
generateAsySecret
(
globalECDHData
,
globalPriKey
,
globalPubKey
);
})
.
then
((
result
)
=>
{
console
.
warn
(
"
result data is
"
+
uInt8ArrayToShowStr
(
result
.
data
));
expect
(
result
!=
null
).
assertTrue
();
reject
();
})
.
catch
((
err
)
=>
{
console
.
error
(
"
[Callback] keyAgreementProcess catch err:
"
+
err
);
resolve
(
err
);
});
});
}
async
function
keyAgreementProcessParameterException
(
ECDHAlgoName
)
{
var
globalPubKey
;
var
globalPriKey
;
return
new
Promise
((
resolve
,
reject
)
=>
{
var
rsaGenerator
=
createAsyKeyGenerator
(
ECDHAlgoName
);
expect
(
rsaGenerator
!=
null
).
assertTrue
();
var
globalECDHData
=
createAsyKeyAgreement
(
ECDHAlgoName
);
expect
(
globalECDHData
!=
null
).
assertTrue
();
generateAsyKeyPair
(
rsaGenerator
)
.
then
((
rsaKeyPair
)
=>
{
expect
(
rsaKeyPair
!=
null
).
assertTrue
();
globalPubKey
=
rsaKeyPair
.
pubKey
;
globalPriKey
=
rsaKeyPair
.
priKey
;
return
generateAsySecret
(
globalECDHData
,
null
,
null
);
})
.
then
((
result
)
=>
{
console
.
warn
(
"
result data is
"
+
uInt8ArrayToShowStr
(
result
.
data
));
expect
(
result
!=
null
).
assertTrue
();
})
.
catch
((
err
)
=>
{
expect
(
err
==
"
Error: [PriKey]: param unwarp error.
"
).
assertTrue
();
});
generateAsyKeyPair
(
rsaGenerator
)
.
then
((
rsaKeyPair
)
=>
{
expect
(
rsaKeyPair
!=
null
).
assertTrue
();
globalPubKey
=
rsaKeyPair
.
pubKey
;
globalPriKey
=
rsaKeyPair
.
priKey
;
return
generateAsySecret
(
globalECDHData
,
globalPubKey
,
null
);
})
.
then
((
result
)
=>
{
console
.
warn
(
"
result data is
"
+
uInt8ArrayToShowStr
(
result
.
data
));
expect
(
result
!=
null
).
assertTrue
();
})
.
catch
((
err
)
=>
{
expect
(
err
==
"
Error: [PubKey]: param unwarp error.
"
).
assertTrue
();
});
generateAsyKeyPair
(
rsaGenerator
)
.
then
((
rsaKeyPair
)
=>
{
expect
(
rsaKeyPair
!=
null
).
assertTrue
();
globalPubKey
=
rsaKeyPair
.
pubKey
;
globalPriKey
=
rsaKeyPair
.
priKey
;
return
generateAsySecret
(
globalECDHData
,
null
,
globalPriKey
);
})
.
then
((
result
)
=>
{
console
.
warn
(
"
result data is
"
+
uInt8ArrayToShowStr
(
result
.
data
));
expect
(
result
!=
null
).
assertTrue
();
reject
();
})
.
catch
((
err
)
=>
{
expect
(
err
==
"
Error: [PriKey]: param unwarp error.
"
).
assertTrue
();
resolve
(
err
);
});
});
}
async
function
createAsyKeyGeneratorFail
(
asyAlgoName
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
var
rsaGenerator
=
createAsyKeyGenerator
(
asyAlgoName
);
resolve
(
rsaGenerator
);
expect
(
rsaGenerator
==
"
TypeError: Cannot read property algName of null
"
).
assertTrue
();
if
(
rsaGenerator
!=
"
TypeError: Cannot read property algName of null
"
)
{
reject
();
}
});
}
async
function
encryptAndDecryptNormalProcessSuperdata
(
asyAlgoName
,
cipherAlgoName
,
globalTextLen
)
{
var
globalCipherText
;
var
globalPubKey
;
var
globalPriKey
;
var
globalText
;
var
i
;
var
encryptMode
=
cryptoFramework
.
CryptoMode
.
ENCRYPT_MODE
;
var
decryptMode
=
cryptoFramework
.
CryptoMode
.
DECRYPT_MODE
;
var
t
=
"
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefhijklmnopqrstuvwxyz
"
,
n
=
t
.
length
,
s
=
""
;
for
(
i
=
0
;
i
<
globalTextLen
;
i
++
)
{
globalText
+=
t
.
charAt
(
Math
.
floor
(
Math
.
random
()
*
n
));
}
var
input
=
{
data
:
stringTouInt8Array
(
globalText
)
};
return
new
Promise
((
resolve
,
reject
)
=>
{
var
rsaGenerator
=
createAsyKeyGenerator
(
asyAlgoName
);
expect
(
rsaGenerator
!=
null
).
assertTrue
();
var
cipherGeneratorEncrypt
=
createAsyCipher
(
cipherAlgoName
);
expect
(
cipherGeneratorEncrypt
!=
null
).
assertTrue
();
var
cipherGeneratorDecrypt
=
createAsyCipher
(
cipherAlgoName
);
expect
(
cipherGeneratorDecrypt
!=
null
).
assertTrue
();
generateAsyKeyPair
(
rsaGenerator
)
.
then
((
rsaKeyPair
)
=>
{
expect
(
rsaKeyPair
!=
null
).
assertTrue
();
globalPubKey
=
rsaKeyPair
.
pubKey
;
globalPriKey
=
rsaKeyPair
.
priKey
;
return
initCipher
(
cipherGeneratorEncrypt
,
encryptMode
,
globalPubKey
,
null
);
})
.
then
((
initData
)
=>
{
expect
(
initData
===
"
init success
"
).
assertTrue
();
return
doFinalCipher
(
cipherGeneratorEncrypt
,
encryptMode
,
input
);
})
.
then
((
finalOutput
)
=>
{
expect
(
finalOutput
!=
null
).
assertTrue
();
globalCipherText
=
finalOutput
;
console
.
log
(
"
cipherOutput:
"
+
uInt8ArrayToShowStr
(
globalCipherText
.
data
)
);
return
initCipher
(
cipherGeneratorDecrypt
,
decryptMode
,
globalPriKey
,
null
);
})
.
then
((
initData
)
=>
{
expect
(
initData
===
"
init success
"
).
assertTrue
();
return
doFinalCipher
(
cipherGeneratorDecrypt
,
decryptMode
,
globalCipherText
);
})
.
then
((
finalOutput
)
=>
{
if
(
finalOutput
==
null
)
{
console
.
error
(
"
[Callback]decrypt doFinal out is null
"
);
}
else
{
console
.
log
(
"
[Callback]decrypt doFinal out hex:
"
+
uInt8ArrayToShowStr
(
finalOutput
.
data
)
);
}
let
decryptData
=
uInt8ArrayToString
(
finalOutput
.
data
);
expect
(
decryptData
==
globalText
).
assertTrue
();
resolve
();
})
.
catch
((
err
)
=>
{
console
.
error
(
"
[Callback] encryptAndDecryptNormalProcess catch err:
"
+
err
);
reject
(
err
);
});
});
}
async
function
signAndVerifyNormalProcessSuperdata
(
asyAlgoName
,
signVerifyAlgoName
,
globalTextLen
)
{
var
globalSignBlob
;
var
globalPubKey
;
var
globalPriKey
;
var
globalText
;
var
i
;
var
t
=
"
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefhijklmnopqrstuvwxyz
"
,
n
=
t
.
length
,
s
=
""
;
for
(
i
=
0
;
i
<
globalTextLen
;
i
++
)
{
globalText
+=
t
.
charAt
(
Math
.
floor
(
Math
.
random
()
*
n
));
}
var
input
=
{
data
:
stringTouInt8Array
(
globalText
)
};
return
new
Promise
((
resolve
,
reject
)
=>
{
var
rsaGenerator
=
createAsyKeyGenerator
(
asyAlgoName
);
expect
(
rsaGenerator
!=
null
).
assertTrue
();
var
signGenerator
=
createAsySign
(
signVerifyAlgoName
);
expect
(
signGenerator
!=
null
).
assertTrue
();
var
verifyGenerator
=
createAsyVerify
(
signVerifyAlgoName
);
expect
(
verifyGenerator
!=
null
).
assertTrue
();
generateAsyKeyPair
(
rsaGenerator
)
.
then
((
rsaKeyPair
)
=>
{
expect
(
rsaKeyPair
!=
null
).
assertTrue
();
globalPubKey
=
rsaKeyPair
.
pubKey
;
globalPriKey
=
rsaKeyPair
.
priKey
;
return
initSign
(
signGenerator
,
globalPriKey
);
})
.
then
((
initData
)
=>
{
expect
(
initData
===
"
init success
"
).
assertTrue
();
return
updateSign
(
signGenerator
,
input
);
})
.
then
((
updateData
)
=>
{
expect
(
updateData
===
"
update success
"
).
assertTrue
();
return
signForSign
(
signGenerator
,
input
);
})
.
then
((
finalOutput
)
=>
{
expect
(
finalOutput
!=
null
).
assertTrue
();
globalSignBlob
=
finalOutput
;
console
.
log
(
"
signOutput:
"
+
uInt8ArrayToShowStr
(
globalSignBlob
.
data
));
return
initVerify
(
verifyGenerator
,
globalPubKey
);
})
.
then
((
initData
)
=>
{
expect
(
initData
===
"
init success
"
).
assertTrue
();
return
updateVerify
(
verifyGenerator
,
input
);
})
.
then
((
updateData
)
=>
{
expect
(
updateData
===
"
update success
"
).
assertTrue
();
return
verifyForVerify
(
verifyGenerator
,
input
,
globalSignBlob
);
})
.
then
((
finalStatus
)
=>
{
expect
(
finalStatus
).
assertTrue
();
resolve
();
})
.
catch
((
err
)
=>
{
console
.
error
(
"
[Callback] signAndVerifyNormalProcess catch err:
"
+
err
);
reject
(
err
);
});
});
}
async
function
encryptAndDecryptNormalProcessNull
(
asyAlgoName
,
cipherAlgoName
)
{
var
globalCipherText
;
var
globalPubKey
;
var
globalPriKey
;
var
encryptMode
=
cryptoFramework
.
CryptoMode
.
ENCRYPT_MODE
;
var
decryptMode
=
cryptoFramework
.
CryptoMode
.
DECRYPT_MODE
;
return
new
Promise
((
resolve
,
reject
)
=>
{
var
rsaGenerator
=
createAsyKeyGenerator
(
asyAlgoName
);
expect
(
rsaGenerator
!=
null
).
assertTrue
();
var
cipherGeneratorEncrypt
=
createAsyCipher
(
cipherAlgoName
);
expect
(
cipherGeneratorEncrypt
!=
null
).
assertTrue
();
var
cipherGeneratorDecrypt
=
createAsyCipher
(
cipherAlgoName
);
expect
(
cipherGeneratorDecrypt
!=
null
).
assertTrue
();
generateAsyKeyPair
(
rsaGenerator
)
.
then
((
rsaKeyPair
)
=>
{
expect
(
rsaKeyPair
!=
null
).
assertTrue
();
globalPubKey
=
rsaKeyPair
.
pubKey
;
globalPriKey
=
rsaKeyPair
.
priKey
;
return
initCipher
(
cipherGeneratorEncrypt
,
encryptMode
,
globalPubKey
,
null
);
})
.
then
((
initData
)
=>
{
expect
(
initData
===
"
init success
"
).
assertTrue
();
return
doFinalCipher
(
cipherGeneratorEncrypt
,
encryptMode
,
null
);
})
.
then
((
finalOutput
)
=>
{
expect
(
finalOutput
!=
null
).
assertTrue
();
globalCipherText
=
finalOutput
;
console
.
log
(
"
cipherOutput:
"
+
uInt8ArrayToShowStr
(
globalCipherText
.
data
)
);
return
initCipher
(
cipherGeneratorDecrypt
,
decryptMode
,
globalPriKey
,
null
);
})
.
then
((
initData
)
=>
{
expect
(
initData
===
"
init success
"
).
assertTrue
();
return
doFinalCipher
(
cipherGeneratorDecrypt
,
decryptMode
,
globalCipherText
);
})
.
then
((
finalOutput
)
=>
{
if
(
finalOutput
==
null
)
{
console
.
error
(
"
[Callback]decrypt doFinal out is null
"
);
}
else
{
console
.
log
(
"
[Callback]decrypt doFinal out hex:
"
+
uInt8ArrayToShowStr
(
finalOutput
.
data
)
);
}
let
decryptData
=
uInt8ArrayToString
(
finalOutput
.
data
);
expect
(
decryptData
==
globalText
).
assertTrue
();
reject
();
})
.
catch
((
err
)
=>
{
console
.
error
(
"
[Callback] encryptAndDecryptNormalProcess catch err:
"
+
err
);
resolve
(
err
);
});
});
}
export
{
encryptAndDecryptNormalProcess
,
signAndVerifyNormalProcess
,
convertKeyEncryptAndDecryptProcess
,
keyAgreementProcess
,
createAsyKeyAgreementFail
,
keyAgreementProcessFail
,
keyAgreementProcessParameterException
,
createAsyKeyGeneratorFail
,
encryptAndDecryptNormalProcessSuperdata
,
signAndVerifyNormalProcessSuperdata
,
encryptAndDecryptNormalProcessNull
,
};
security/cryptoFramework/js_api_test_one/src/main/js/test/utils/asymmetric/publicAsymmetricPromise.js
浏览文件 @
dd14b5d7
...
...
@@ -351,6 +351,74 @@ async function signAndVerifyNormalProcess(asyAlgoName, signVerifyAlgoName) {
});
}
async
function
signAndVerifyNormalProcessDataException
(
asyAlgoName
,
signVerifyAlgoName
,
dataType
)
{
var
globalPubKey
;
var
globalPriKey
;
var
globalSignBlob
;
var
globalText
=
"
This is a sign test
"
;
var
input
;
if
(
dataType
==
"
null
"
)
{
input
=
null
;
}
else
{
input
=
{
data
:
stringTouInt8Array
(
globalText
)
};
};
return
new
Promise
((
resolve
,
reject
)
=>
{
var
rsaGenerator
=
createAsyKeyGenerator
(
asyAlgoName
);
expect
(
rsaGenerator
!=
null
).
assertTrue
();
var
signGenerator
=
createAsySign
(
signVerifyAlgoName
);
expect
(
signGenerator
!=
null
).
assertTrue
();
var
verifyGenerator
=
createAsyVerify
(
signVerifyAlgoName
);
expect
(
verifyGenerator
!=
null
).
assertTrue
();
generateAsyKeyPair
(
rsaGenerator
)
.
then
((
rsaKeyPair
)
=>
{
expect
(
rsaKeyPair
!=
null
).
assertTrue
();
globalPubKey
=
rsaKeyPair
.
pubKey
;
globalPriKey
=
rsaKeyPair
.
priKey
;
return
initSign
(
signGenerator
,
globalPriKey
);
})
.
then
((
initData
)
=>
{
expect
(
initData
===
"
init success
"
).
assertTrue
();
return
updateSign
(
signGenerator
,
input
);
})
.
then
((
updateData
)
=>
{
expect
(
updateData
===
"
update success
"
).
assertTrue
();
return
signForSign
(
signGenerator
,
input
);
})
.
then
((
finalOutput
)
=>
{
expect
(
finalOutput
!=
null
).
assertTrue
();
globalSignBlob
=
finalOutput
;
console
.
log
(
"
signOutput:
"
+
uInt8ArrayToShowStr
(
globalSignBlob
.
data
));
return
initVerify
(
verifyGenerator
,
globalPubKey
);
})
.
then
((
initData
)
=>
{
expect
(
initData
===
"
init success
"
).
assertTrue
();
return
updateVerify
(
verifyGenerator
,
input
);
})
.
then
((
updateData
)
=>
{
expect
(
updateData
===
"
update success
"
).
assertTrue
();
return
verifyForVerify
(
verifyGenerator
,
input
,
globalSignBlob
);
})
.
then
((
finalStatus
)
=>
{
expect
(
finalStatus
).
assertTrue
();
if
(
dataType
==
"
null
"
)
{
reject
();
}
else
{
resolve
();
}
})
.
catch
((
err
)
=>
{
console
.
error
(
"
[promise] signAndVerifyNormalProcess catch err:
"
+
err
);
if
(
dataType
==
"
null
"
)
{
resolve
(
err
);
}
else
{
reject
(
err
);
}
});
});
}
async
function
convertKeyEncryptAndDecryptProcess
(
asyAlgoName
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
var
rsaGenerator
=
createAsyKeyGenerator
(
asyAlgoName
);
...
...
@@ -445,10 +513,84 @@ async function AsyPriKeyClearProcess(asyAlgoName) {
});
}
async
function
createAsyKeyGeneratorFail
(
asyAlgoName
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
var
rsaGenerator
=
createAsyKeyGenerator
(
asyAlgoName
);
resolve
(
rsaGenerator
);
expect
(
rsaGenerator
==
"
TypeError: Cannot read property algName of null
"
).
assertTrue
();
if
(
rsaGenerator
!=
"
TypeError: Cannot read property algName of null
"
)
{
reject
();
}
});
}
async
function
createAsySignFail
(
asyAlgoName
,
signVerifyAlgoName
,
signVerifyAlgoName1
,
signVerifyAlgoName2
,
signVerifyAlgoName3
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
var
rsaGenerator
=
createAsyKeyGenerator
(
asyAlgoName
);
expect
(
rsaGenerator
!=
null
).
assertTrue
();
var
rsaKeyPair
=
generateAsyKeyPair
(
rsaGenerator
);
expect
(
rsaKeyPair
!=
null
).
assertTrue
();
var
signGenerator
=
createAsySign
(
signVerifyAlgoName
);
expect
(
signGenerator
==
"
TypeError: Cannot read property algName of undefined
"
).
assertTrue
();
var
signGenerator
=
createAsySign
(
signVerifyAlgoName1
);
expect
(
signGenerator
==
"
TypeError: Cannot read property algName of undefined
"
).
assertTrue
();
var
signGenerator
=
createAsySign
(
signVerifyAlgoName2
);
expect
(
signGenerator
==
"
TypeError: Cannot read property algName of undefined
"
).
assertTrue
();
var
signGenerator
=
createAsySign
(
signVerifyAlgoName3
);
resolve
(
signGenerator
);
expect
(
signGenerator
==
"
TypeError: Cannot read property algName of undefined
"
).
assertTrue
();
if
(
signGenerator
!=
"
TypeError: Cannot read property algName of undefined
"
)
{
reject
();
}
});
}
async
function
createAsyVerifyFail
(
asyAlgoName
,
signVerifyAlgoName
,
signVerifyAlgoName1
,
signVerifyAlgoName2
,
signVerifyAlgoName3
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
var
rsaGenerator
=
createAsyKeyGenerator
(
asyAlgoName
);
expect
(
rsaGenerator
!=
null
).
assertTrue
();
var
rsaKeyPair
=
generateAsyKeyPair
(
rsaGenerator
);
expect
(
rsaKeyPair
!=
null
).
assertTrue
();
var
verifyGenerator
=
createAsyVerify
(
signVerifyAlgoName
);
expect
(
verifyGenerator
==
"
TypeError: Cannot read property algName of undefined
"
).
assertTrue
();
var
verifyGenerator
=
createAsyVerify
(
signVerifyAlgoName1
);
expect
(
verifyGenerator
==
"
TypeError: Cannot read property algName of undefined
"
).
assertTrue
();
var
verifyGenerator
=
createAsyVerify
(
signVerifyAlgoName2
);
expect
(
verifyGenerator
==
"
TypeError: Cannot read property algName of undefined
"
).
assertTrue
();
var
verifyGenerator
=
createAsyVerify
(
signVerifyAlgoName3
);
resolve
(
verifyGenerator
);
expect
(
verifyGenerator
==
"
TypeError: Cannot read property algName of undefined
"
).
assertTrue
();
if
(
verifyGenerator
!=
"
TypeError: Cannot read property algName of undefined
"
)
{
reject
();
}
});
}
export
{
encryptAndDecryptNormalProcess
,
signAndVerifyNormalProcess
,
convertKeyEncryptAndDecryptProcess
,
keyAgreementProcess
,
AsyPriKeyClearProcess
,
signAndVerifyNormalProcessDataException
,
createAsyKeyGeneratorFail
,
createAsySignFail
,
createAsyVerifyFail
,
};
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录