Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Xts Acts
提交
28e11006
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看板
未验证
提交
28e11006
编写于
11月 17, 2022
作者:
O
openharmony_ci
提交者:
Gitee
11月 17, 2022
浏览文件
操作
浏览文件
下载
差异文件
!6560 【OpenHarmony 3.2.8.5】【安全子系统】【master】加解密新增用例
Merge pull request !6560 from qiaozzzh/1117_1
上级
6bbce048
140e8ca3
变更
5
展开全部
显示空白变更内容
内联
并排
Showing
5 changed file
with
1188 addition
and
44 deletion
+1188
-44
security/cryptoFramework/js_api_test_one/src/main/js/test/DigestAlgorithm.test.js
.../js_api_test_one/src/main/js/test/DigestAlgorithm.test.js
+17
-17
security/cryptoFramework/js_api_test_one/src/main/js/test/SymmetricCryptography.test.js
...i_test_one/src/main/js/test/SymmetricCryptography.test.js
+856
-5
security/cryptoFramework/js_api_test_one/src/main/js/test/utils/symmetric/publicSymmetricCallback.js
...c/main/js/test/utils/symmetric/publicSymmetricCallback.js
+21
-9
security/cryptoFramework/js_api_test_one/src/main/js/test/utils/symmetric/publicSymmetricPromise.js
...rc/main/js/test/utils/symmetric/publicSymmetricPromise.js
+289
-8
security/cryptoFramework/js_api_test_two/src/main/js/test/SecurityRandom.test.js
...k/js_api_test_two/src/main/js/test/SecurityRandom.test.js
+5
-5
未找到文件。
security/cryptoFramework/js_api_test_one/src/main/js/test/DigestAlgorithm.test.js
浏览文件 @
28e11006
...
...
@@ -55,7 +55,7 @@ export default function DigestAlgorithmJsunit() {
/**
* @tc.number Security_crypto_framework_MD_0200
* @tc.name Test
MD5
for MD digest algotithm
* @tc.name Test
SHA1
for MD digest algotithm
* @tc.desc Use the Promise Style of Interface
*/
it
(
"
Security_crypto_framework_MD_0200
"
,
0
,
async
function
(
done
)
{
...
...
@@ -71,7 +71,7 @@ export default function DigestAlgorithmJsunit() {
/**
* @tc.number Security_crypto_framework_MD_0300
* @tc.name Test
MD5
for MD digest algotithm
* @tc.name Test
SHA224
for MD digest algotithm
* @tc.desc Use the Promise Style of Interface
*/
it
(
"
Security_crypto_framework_MD_0300
"
,
0
,
async
function
(
done
)
{
...
...
@@ -87,7 +87,7 @@ export default function DigestAlgorithmJsunit() {
/**
* @tc.number Security_crypto_framework_MD_0400
* @tc.name Test SHA
384
for MD digest algotithm
* @tc.name Test SHA
256
for MD digest algotithm
* @tc.desc Use the Callback Style of Interface
*/
it
(
"
Security_crypto_framework_MD_0400
"
,
0
,
async
function
(
done
)
{
...
...
@@ -102,7 +102,7 @@ export default function DigestAlgorithmJsunit() {
});
/**
* @tc.number Security_crypto_framework_MD_
* @tc.number Security_crypto_framework_MD_
0500
*
* @tc.name Test SHA384 for MD digest algotithm
* @tc.desc Use the Callback Style of Interface
...
...
@@ -120,7 +120,7 @@ export default function DigestAlgorithmJsunit() {
/**
* @tc.number Security_crypto_framework_MD_0600
* @tc.name Test SHA
384
for MD digest algotithm
* @tc.name Test SHA
512
for MD digest algotithm
* @tc.desc Use the Callback Style of Interface
*/
it
(
"
Security_crypto_framework_MD_0600
"
,
0
,
async
function
(
done
)
{
...
...
@@ -136,7 +136,7 @@ export default function DigestAlgorithmJsunit() {
/**
* @tc.number Security_crypto_framework_MD_0700
* @tc.name T
est SHA384 for MD digest algotithm
* @tc.name T
he encryption and decryption framework supports MD calculation, and the algorithm parameters are abnormal
* @tc.desc Use the Callback Style of Interface
*/
it
(
"
Security_crypto_framework_MD_0700
"
,
0
,
async
function
(
done
)
{
...
...
@@ -152,7 +152,7 @@ export default function DigestAlgorithmJsunit() {
/**
* @tc.number Security_crypto_framework_MD_0800
* @tc.name T
est SHA384 for MD digest algotithm
* @tc.name T
he encryption and decryption framework supports MD calculation, and the algorithm parameter is NULL
* @tc.desc Use the Callback Style of Interface
*/
it
(
"
Security_crypto_framework_MD_0800
"
,
0
,
async
function
(
done
)
{
...
...
@@ -168,7 +168,7 @@ export default function DigestAlgorithmJsunit() {
/**
* @tc.number Security_crypto_framework_MD_0900
* @tc.name T
est SHA384 for MD digest algotithm
* @tc.name T
he encryption and decryption framework supports MD calculation, and the Datablob value to be calculated is a super large value
* @tc.desc Use the Callback Style of Interface
*/
it
(
"
Security_crypto_framework_MD_0900
"
,
0
,
async
function
(
done
)
{
...
...
@@ -184,7 +184,7 @@ export default function DigestAlgorithmJsunit() {
/**
* @tc.number Security_crypto_framework_MD_1000
* @tc.name T
est SHA384 for MD digest algotithm
* @tc.name T
he encryption and decryption framework supports MD calculation, and the Datablob value to be calculated is abnormal
* @tc.desc Use the Callback Style of Interface
*/
it
(
"
Security_crypto_framework_MD_1000
"
,
0
,
async
function
(
done
)
{
...
...
@@ -216,7 +216,7 @@ export default function DigestAlgorithmJsunit() {
/**
* @tc.number Security_crypto_framework_HMAC_0200
* @tc.name Test SHA
1
for HMAC digest algorithm
* @tc.name Test SHA
224
for HMAC digest algorithm
* @tc.desc Use the Promise Style of Interface
*/
it
(
"
Security_crypto_framework_HMAC_0200
"
,
0
,
async
function
(
done
)
{
...
...
@@ -232,7 +232,7 @@ export default function DigestAlgorithmJsunit() {
/**
* @tc.number Security_crypto_framework_HMAC_0300
* @tc.name Test SHA
1
for HMAC digest algorithm
* @tc.name Test SHA
256
for HMAC digest algorithm
* @tc.desc Use the Callback Style of Interface
*/
it
(
"
Security_crypto_framework_HMAC_0300
"
,
0
,
async
function
(
done
)
{
...
...
@@ -248,7 +248,7 @@ export default function DigestAlgorithmJsunit() {
/**
* @tc.number Security_crypto_framework_HMAC_0400
* @tc.name Test SHA
1
for HMAC digest algorithm
* @tc.name Test SHA
384
for HMAC digest algorithm
* @tc.desc Use the Promise Style of Interface
*/
it
(
"
Security_crypto_framework_HMAC_0400
"
,
0
,
async
function
(
done
)
{
...
...
@@ -264,7 +264,7 @@ export default function DigestAlgorithmJsunit() {
/**
* @tc.number Security_crypto_framework_HMAC_0500
* @tc.name Test SHA
1
for HMAC digest algorithm
* @tc.name Test SHA
512
for HMAC digest algorithm
* @tc.desc Use the Promise Style of Interface
*/
it
(
"
Security_crypto_framework_HMAC_0500
"
,
0
,
async
function
(
done
)
{
...
...
@@ -280,7 +280,7 @@ export default function DigestAlgorithmJsunit() {
/**
* @tc.number Security_crypto_framework_HMAC_0600
* @tc.name T
est SHA1 for HMAC digest algorithm
* @tc.name T
he encryption and decryption framework supports HMAC calculation, and HMAC algorithm parameters are abnormal
* @tc.desc Use the Promise Style of Interface
*/
it
(
"
Security_crypto_framework_HMAC_0600
"
,
0
,
async
function
(
done
)
{
...
...
@@ -296,7 +296,7 @@ export default function DigestAlgorithmJsunit() {
/**
* @tc.number Security_crypto_framework_HMAC_0700
* @tc.name T
est SHA1 for HMAC digest algorithm
* @tc.name T
he encryption and decryption framework supports HMAC calculation, and the key algorithm parameters are abnormal
* @tc.desc Use the Promise Style of Interface
*/
it
(
"
Security_crypto_framework_HMAC_0700
"
,
0
,
async
function
(
done
)
{
...
...
@@ -312,7 +312,7 @@ export default function DigestAlgorithmJsunit() {
/**
* @tc.number Security_crypto_framework_HMAC_0800
* @tc.name T
est SHA1 for HMAC digest algorithm
* @tc.name T
he encryption and decryption framework supports HMAC calculation, and the Datablob of HMAC to be calculated is abnormal
* @tc.desc Use the Promise Style of Interface
*/
it
(
"
Security_crypto_framework_HMAC_0800
"
,
0
,
async
function
(
done
)
{
...
...
@@ -328,7 +328,7 @@ export default function DigestAlgorithmJsunit() {
/**
* @tc.number Security_crypto_framework_HMAC_0900
* @tc.name T
est SHA1 for HMAC digest algorithm
* @tc.name T
he encryption and decryption framework supports HMAC calculation, and the Datablob of HMAC to be calculated is very large
* @tc.desc Use the Promise Style of Interface
*/
it
(
"
Security_crypto_framework_HMAC_0900
"
,
0
,
async
function
(
done
)
{
...
...
security/cryptoFramework/js_api_test_one/src/main/js/test/SymmetricCryptography.test.js
浏览文件 @
28e11006
此差异已折叠。
点击以展开。
security/cryptoFramework/js_api_test_one/src/main/js/test/utils/symmetric/publicSymmetricCallback.js
浏览文件 @
28e11006
...
...
@@ -156,6 +156,7 @@ async function encryptAndDecryptNormalProcess(
cipherAlgoName
,
paramType
)
{
var
updateOutputdata
;
var
globalCipherText
;
var
globalKey
;
var
globalText
=
"
aaa this is test! this is test! bbb
"
;
...
...
@@ -230,13 +231,11 @@ async function encryptAndDecryptNormalProcess(
return
updateCipher
(
cipherGenerator
,
decryptMode
,
globalCipherText
);
})
.
then
((
updateOutput
)
=>
{
updateOutputdata
=
uInt8ArrayToString
(
updateOutput
.
data
);
console
.
warn
(
"
[Callback]decrypt update out:
"
+
uInt8ArrayToString
(
updateOutput
.
data
)
);
expect
(
uInt8ArrayToString
(
updateOutput
.
data
)
==
globalText
).
assertTrue
();
return
doFinalCipher
(
cipherGenerator
,
decryptMode
,
null
);
})
.
then
((
finalOutput
)
=>
{
...
...
@@ -245,8 +244,15 @@ async function encryptAndDecryptNormalProcess(
}
else
{
console
.
log
(
"
[Callback]decrypt doFinal out hex:
"
+
uInt8ArrayToShowStr
(
finalOutput
.
data
)
uInt8ArrayToString
(
finalOutput
.
data
)
);
console
.
log
(
"
[Callback]Decrypt plaintext data:
"
+
updateOutputdata
+
uInt8ArrayToString
(
finalOutput
.
data
)
);
expect
(
updateOutputdata
+
uInt8ArrayToString
(
finalOutput
.
data
)
==
globalText
).
assertTrue
();
}
resolve
();
})
...
...
@@ -262,6 +268,7 @@ async function convertKeyEncryptAndDecryptProcess(
cipherAlgoName
,
paramType
)
{
var
updateOutputdata
;
var
globalCipherText
;
var
globalKey
;
var
globalText
=
"
aaa this is test! this is test! bbb
"
;
...
...
@@ -341,13 +348,11 @@ async function convertKeyEncryptAndDecryptProcess(
return
updateCipher
(
cipherGenerator
,
decryptMode
,
globalCipherText
);
})
.
then
((
updateOutput
)
=>
{
updateOutputdata
=
uInt8ArrayToString
(
updateOutput
.
data
);
console
.
warn
(
"
[Callback]decrypt update out:
"
+
uInt8ArrayToString
(
updateOutput
.
data
)
);
expect
(
uInt8ArrayToString
(
updateOutput
.
data
)
==
globalText
).
assertTrue
();
return
doFinalCipher
(
cipherGenerator
,
decryptMode
,
null
);
})
.
then
((
finalOutput
)
=>
{
...
...
@@ -355,9 +360,16 @@ async function convertKeyEncryptAndDecryptProcess(
console
.
error
(
"
[Callback]decrypt doFinal out is null
"
);
}
else
{
console
.
log
(
"
[
Callback
]decrypt doFinal out hex:
"
+
uInt8ArrayToShowStr
(
finalOutput
.
data
)
"
[
promise
]decrypt doFinal out hex:
"
+
uInt8ArrayToString
(
finalOutput
.
data
)
);
console
.
log
(
"
[promise]Decrypt plaintext data:
"
+
updateOutputdata
+
uInt8ArrayToString
(
finalOutput
.
data
)
);
expect
(
updateOutputdata
+
uInt8ArrayToString
(
finalOutput
.
data
)
==
globalText
).
assertTrue
();
}
resolve
();
})
...
...
security/cryptoFramework/js_api_test_one/src/main/js/test/utils/symmetric/publicSymmetricPromise.js
浏览文件 @
28e11006
...
...
@@ -154,14 +154,41 @@ async function doFinalCipher(cipherGenerator, mode, dataBlob) {
});
}
async
function
encryptAndDecryptNormalProcess
(
async
function
createSymKeyGeneratorFail
(
symAlgoName
,
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
var
symKeyGenerator
=
createSymKeyGenerator
(
symAlgoName
);
resolve
(
symKeyGenerator
);
expect
(
symKeyGenerator
==
"
Error: create C generator fail.
"
).
assertTrue
();
if
(
symKeyGenerator
!=
"
Error: create C generator fail.
"
)
{
reject
();
}
});
}
async
function
createSymCipherFail
(
cipherAlgoName
,
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
var
symKeyGenerator
=
createSymCipher
(
cipherAlgoName
);
resolve
(
symKeyGenerator
);
expect
(
symKeyGenerator
==
"
Error: create C cipher fail!
"
).
assertTrue
();
if
(
symKeyGenerator
!=
"
Error: create C cipher fail!
"
)
{
reject
();
}
});
}
async
function
encryptAndDecryptNormalProcessSpecialdata
(
symAlgoName
,
cipherAlgoName
,
paramType
)
{
var
updateOutputdata
;
var
globalCipherText
;
var
globalKey
;
var
globalText
=
"
aaa this is test! this is test! bbb
"
;
var
globalText
=
null
;
var
encryptMode
=
cryptoFramework
.
CryptoMode
.
ENCRYPT_MODE
;
var
decryptMode
=
cryptoFramework
.
CryptoMode
.
DECRYPT_MODE
;
...
...
@@ -169,6 +196,9 @@ async function encryptAndDecryptNormalProcess(
var
symKeyGenerator
=
createSymKeyGenerator
(
symAlgoName
);
expect
(
symKeyGenerator
!=
null
).
assertTrue
();
var
cipherGenerator
=
createSymCipher
(
cipherAlgoName
);
if
(
cipherGenerator
==
"
Error: create C cipher fail!
"
)
{
resolve
(
cipherGenerator
);
}
expect
(
cipherGenerator
!=
null
).
assertTrue
();
var
globalParams
=
createGlobalParams
(
symAlgoName
,
paramType
);
...
...
@@ -233,13 +263,126 @@ async function encryptAndDecryptNormalProcess(
return
updateCipher
(
cipherGenerator
,
decryptMode
,
globalCipherText
);
})
.
then
((
updateOutput
)
=>
{
updateOutputdata
=
uInt8ArrayToString
(
updateOutput
.
data
);
console
.
warn
(
"
[promise]decrypt update out:
"
+
uInt8ArrayToString
(
updateOutput
.
data
)
);
return
doFinalCipher
(
cipherGenerator
,
decryptMode
,
null
);
})
.
then
((
finalOutput
)
=>
{
if
(
finalOutput
==
null
)
{
console
.
error
(
"
[promise]decrypt doFinal out is null
"
);
}
else
{
console
.
log
(
"
[promise]decrypt doFinal out hex:
"
+
uInt8ArrayToString
(
finalOutput
.
data
)
);
console
.
log
(
"
[promise]Decrypt plaintext data:
"
+
updateOutputdata
+
uInt8ArrayToString
(
finalOutput
.
data
)
);
expect
(
uInt8ArrayToString
(
update
Output
.
data
)
==
globalText
updateOutputdata
+
uInt8ArrayToString
(
final
Output
.
data
)
==
globalText
).
assertTrue
();
}
reject
();
})
.
catch
((
err
)
=>
{
console
.
error
(
"
[promise] encryptProcess catch err:
"
+
err
);
resolve
(
err
);
});
});
}
async
function
encryptAndDecryptNormalProcess
(
symAlgoName
,
cipherAlgoName
,
paramType
)
{
var
updateOutputdata
;
var
globalCipherText
;
var
globalKey
;
var
globalText
=
"
aaa this is test! this is test! bbb
"
;
var
encryptMode
=
cryptoFramework
.
CryptoMode
.
ENCRYPT_MODE
;
var
decryptMode
=
cryptoFramework
.
CryptoMode
.
DECRYPT_MODE
;
return
new
Promise
((
resolve
,
reject
)
=>
{
var
symKeyGenerator
=
createSymKeyGenerator
(
symAlgoName
);
expect
(
symKeyGenerator
!=
null
).
assertTrue
();
var
cipherGenerator
=
createSymCipher
(
cipherAlgoName
);
if
(
cipherGenerator
==
"
Error: create C cipher fail!
"
)
{
resolve
(
cipherGenerator
);
}
expect
(
cipherGenerator
!=
null
).
assertTrue
();
var
globalParams
=
createGlobalParams
(
symAlgoName
,
paramType
);
generateSymKey
(
symKeyGenerator
)
.
then
((
promiseKey
)
=>
{
expect
(
promiseKey
!=
null
).
assertTrue
();
globalKey
=
promiseKey
;
return
initCipher
(
cipherGenerator
,
encryptMode
,
promiseKey
,
globalParams
);
})
.
then
((
initData
)
=>
{
expect
(
initData
===
"
init success
"
).
assertTrue
();
let
plainText
=
{
data
:
stringTouInt8Array
(
globalText
)
};
return
updateCipher
(
cipherGenerator
,
encryptMode
,
plainText
);
})
.
then
((
updateOutput
)
=>
{
console
.
warn
(
"
[promise]encrypt update out hex:
"
+
uInt8ArrayToShowStr
(
updateOutput
.
data
)
);
globalCipherText
=
updateOutput
;
expect
(
globalCipherText
!=
null
).
assertTrue
();
return
doFinalCipher
(
cipherGenerator
,
encryptMode
,
null
);
})
.
then
((
finalOutput
)
=>
{
if
(
finalOutput
==
null
)
{
}
else
{
if
(
paramType
==
"
genGcmParamsSpec
"
||
paramType
==
"
genCcmParamsSpec
"
)
{
console
.
warn
(
"
[promise]encrypt authTag(finalOutput) hex:
"
+
uInt8ArrayToShowStr
(
finalOutput
.
data
)
);
globalParams
.
authTag
=
finalOutput
;
}
else
{
console
.
warn
(
"
[promise]encrypt authTag(finalOutput) hex:
"
+
uInt8ArrayToShowStr
(
finalOutput
.
data
)
);
globalCipherText
=
Array
.
from
(
globalCipherText
.
data
);
finalOutput
=
Array
.
from
(
finalOutput
.
data
);
globalCipherText
=
globalCipherText
.
concat
(
finalOutput
);
globalCipherText
=
new
Uint8Array
(
globalCipherText
);
globalCipherText
=
{
data
:
globalCipherText
};
}
}
return
initCipher
(
cipherGenerator
,
decryptMode
,
globalKey
,
globalParams
);
})
.
then
((
initData
)
=>
{
expect
(
initData
===
"
init success
"
).
assertTrue
();
return
updateCipher
(
cipherGenerator
,
decryptMode
,
globalCipherText
);
})
.
then
((
updateOutput
)
=>
{
updateOutputdata
=
uInt8ArrayToString
(
updateOutput
.
data
);
console
.
warn
(
"
[promise]decrypt update out:
"
+
uInt8ArrayToString
(
updateOutput
.
data
)
);
return
doFinalCipher
(
cipherGenerator
,
decryptMode
,
null
);
})
.
then
((
finalOutput
)
=>
{
...
...
@@ -248,8 +391,15 @@ async function encryptAndDecryptNormalProcess(
}
else
{
console
.
log
(
"
[promise]decrypt doFinal out hex:
"
+
uInt8ArrayToShowStr
(
finalOutput
.
data
)
uInt8ArrayToString
(
finalOutput
.
data
)
);
console
.
log
(
"
[promise]Decrypt plaintext data:
"
+
updateOutputdata
+
uInt8ArrayToString
(
finalOutput
.
data
)
);
expect
(
updateOutputdata
+
uInt8ArrayToString
(
finalOutput
.
data
)
==
globalText
).
assertTrue
();
}
resolve
();
})
...
...
@@ -265,6 +415,7 @@ async function convertKeyEncryptAndDecryptProcess(
cipherAlgoName
,
paramType
)
{
var
updateOutputdata
;
var
globalCipherText
;
var
globalKey
;
var
globalText
=
"
aaa this is test! this is test! bbb
"
;
...
...
@@ -344,13 +495,11 @@ async function convertKeyEncryptAndDecryptProcess(
return
updateCipher
(
cipherGenerator
,
decryptMode
,
globalCipherText
);
})
.
then
((
updateOutput
)
=>
{
updateOutputdata
=
uInt8ArrayToString
(
updateOutput
.
data
);
console
.
warn
(
"
[promise]decrypt update out:
"
+
uInt8ArrayToString
(
updateOutput
.
data
)
);
expect
(
uInt8ArrayToString
(
updateOutput
.
data
)
==
globalText
).
assertTrue
();
return
doFinalCipher
(
cipherGenerator
,
decryptMode
,
null
);
})
.
then
((
finalOutput
)
=>
{
...
...
@@ -359,8 +508,15 @@ async function convertKeyEncryptAndDecryptProcess(
}
else
{
console
.
log
(
"
[promise]decrypt doFinal out hex:
"
+
uInt8ArrayToShowStr
(
finalOutput
.
data
)
uInt8ArrayToString
(
finalOutput
.
data
)
);
console
.
log
(
"
[promise]Decrypt plaintext data:
"
+
updateOutputdata
+
uInt8ArrayToString
(
finalOutput
.
data
)
);
expect
(
updateOutputdata
+
uInt8ArrayToString
(
finalOutput
.
data
)
==
globalText
).
assertTrue
();
}
resolve
();
})
...
...
@@ -387,8 +543,133 @@ function ClearMemProcess(symAlgoName) {
});
}
async
function
encryptAndDecryptNormalProcessSuperdata
(
symAlgoName
,
cipherAlgoName
,
paramType
)
{
var
updateOutputdata
;
var
globalCipherText
;
var
globalKey
;
var
globalText
;
var
globalTextLen
=
1025
;
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
));
}
console
.
warn
(
"
globalText1111111111111111111111111111111:
"
+
globalText
);
return
new
Promise
((
resolve
,
reject
)
=>
{
var
symKeyGenerator
=
createSymKeyGenerator
(
symAlgoName
);
expect
(
symKeyGenerator
!=
null
).
assertTrue
();
var
cipherGenerator
=
createSymCipher
(
cipherAlgoName
);
if
(
cipherGenerator
==
"
Error: create C cipher fail!
"
)
{
resolve
(
cipherGenerator
);
}
expect
(
cipherGenerator
!=
null
).
assertTrue
();
var
globalParams
=
createGlobalParams
(
symAlgoName
,
paramType
);
generateSymKey
(
symKeyGenerator
)
.
then
((
promiseKey
)
=>
{
expect
(
promiseKey
!=
null
).
assertTrue
();
globalKey
=
promiseKey
;
return
initCipher
(
cipherGenerator
,
encryptMode
,
promiseKey
,
globalParams
);
})
.
then
((
initData
)
=>
{
expect
(
initData
===
"
init success
"
).
assertTrue
();
let
plainText
=
{
data
:
stringTouInt8Array
(
globalText
)
};
return
updateCipher
(
cipherGenerator
,
encryptMode
,
plainText
);
})
.
then
((
updateOutput
)
=>
{
console
.
warn
(
"
[promise]encrypt update out hex:
"
+
uInt8ArrayToShowStr
(
updateOutput
.
data
)
);
globalCipherText
=
updateOutput
;
expect
(
globalCipherText
!=
null
).
assertTrue
();
return
doFinalCipher
(
cipherGenerator
,
encryptMode
,
null
);
})
.
then
((
finalOutput
)
=>
{
if
(
finalOutput
==
null
)
{
}
else
{
if
(
paramType
==
"
genGcmParamsSpec
"
||
paramType
==
"
genCcmParamsSpec
"
)
{
console
.
warn
(
"
[promise]encrypt authTag(finalOutput) hex:
"
+
uInt8ArrayToShowStr
(
finalOutput
.
data
)
);
globalParams
.
authTag
=
finalOutput
;
}
else
{
console
.
warn
(
"
[promise]encrypt authTag(finalOutput) hex:
"
+
uInt8ArrayToShowStr
(
finalOutput
.
data
)
);
globalCipherText
=
Array
.
from
(
globalCipherText
.
data
);
finalOutput
=
Array
.
from
(
finalOutput
.
data
);
globalCipherText
=
globalCipherText
.
concat
(
finalOutput
);
globalCipherText
=
new
Uint8Array
(
globalCipherText
);
globalCipherText
=
{
data
:
globalCipherText
};
}
}
return
initCipher
(
cipherGenerator
,
decryptMode
,
globalKey
,
globalParams
);
})
.
then
((
initData
)
=>
{
expect
(
initData
===
"
init success
"
).
assertTrue
();
return
updateCipher
(
cipherGenerator
,
decryptMode
,
globalCipherText
);
})
.
then
((
updateOutput
)
=>
{
updateOutputdata
=
uInt8ArrayToString
(
updateOutput
.
data
);
console
.
warn
(
"
[promise]decrypt update out:
"
+
uInt8ArrayToString
(
updateOutput
.
data
)
);
return
doFinalCipher
(
cipherGenerator
,
decryptMode
,
null
);
})
.
then
((
finalOutput
)
=>
{
if
(
finalOutput
==
null
)
{
console
.
error
(
"
[promise]decrypt doFinal out is null
"
);
}
else
{
console
.
log
(
"
[promise]decrypt doFinal out hex:
"
+
uInt8ArrayToString
(
finalOutput
.
data
)
);
console
.
log
(
"
[promise]Decrypt plaintext data:
"
+
updateOutputdata
+
uInt8ArrayToString
(
finalOutput
.
data
)
);
expect
(
updateOutputdata
+
uInt8ArrayToString
(
finalOutput
.
data
)
==
globalText
).
assertTrue
();
}
resolve
();
})
.
catch
((
err
)
=>
{
console
.
error
(
"
[promise] encryptProcess catch err:
"
+
err
);
reject
();
});
});
}
export
{
encryptAndDecryptNormalProcess
,
convertKeyEncryptAndDecryptProcess
,
ClearMemProcess
,
createSymKeyGeneratorFail
,
createSymCipherFail
,
encryptAndDecryptNormalProcessSpecialdata
,
encryptAndDecryptNormalProcessSuperdata
,
};
security/cryptoFramework/js_api_test_two/src/main/js/test/SecurityRandom.test.js
浏览文件 @
28e11006
...
...
@@ -49,7 +49,7 @@ export default function SecurityRandomJsunit() {
/**
* @tc.number Security_crypto_framework_Random_0200
* @tc.name
support security random and set random seed
* @tc.name
Support setting random number seed and restart encryption and decryption framework
* @tc.desc the length of random is 32, use callback style of interface
*/
it
(
"
Security_crypto_framework_Random_0200
"
,
0
,
async
function
(
done
)
{
...
...
@@ -65,8 +65,8 @@ export default function SecurityRandomJsunit() {
/**
* @tc.number Security_crypto_framework_Random_0300
* @tc.name
support security random and set random seed
* @tc.desc
the length of random is 32,
use callback style of interface
* @tc.name
Support generating safe random numbers and setting the length of random numbers
* @tc.desc use callback style of interface
*/
it
(
"
Security_crypto_framework_Random_0300
"
,
0
,
async
function
(
done
)
{
await
testSecurityRandomLengthCallback
(
0
)
...
...
@@ -102,8 +102,8 @@ export default function SecurityRandomJsunit() {
/**
* @tc.number Security_crypto_framework_Random_0400
* @tc.name
support security random and set random seed
* @tc.desc
the length of random is 32,
use callback style of interface
* @tc.name
Support generating safe random numbers and setting random number seed exceptions
* @tc.desc use callback style of interface
*/
it
(
"
Security_crypto_framework_Random_0400
"
,
0
,
async
function
(
done
)
{
await
testSecurityRandomCallbackSeed
(
null
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录