Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Xts Acts
提交
c617ad84
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看板
未验证
提交
c617ad84
编写于
6月 13, 2023
作者:
O
openharmony_ci
提交者:
Gitee
6月 13, 2023
浏览文件
操作
浏览文件
下载
差异文件
!8990 【OpenHarmony 4.0.7.2】【安全子系统】【master】XTS Adaptation requirements
Merge pull request !8990 from qiaozzzh/0612_1
上级
f2809d2c
991ac56a
变更
8
显示空白变更内容
内联
并排
Showing
8 changed file
with
186 addition
and
405 deletion
+186
-405
security/cryptoFramework/js_api_test_one/src/main/js/test/AsymmetricCryptography.test.js
..._test_one/src/main/js/test/AsymmetricCryptography.test.js
+11
-15
security/cryptoFramework/js_api_test_one/src/main/js/test/AsymmetricCryptographySecond.test.js
...one/src/main/js/test/AsymmetricCryptographySecond.test.js
+25
-0
security/cryptoFramework/js_api_test_one/src/main/js/test/DigestAlgorithm.test.js
.../js_api_test_one/src/main/js/test/DigestAlgorithm.test.js
+51
-25
security/cryptoFramework/js_api_test_one/src/main/js/test/SecurityRandom.test.js
...k/js_api_test_one/src/main/js/test/SecurityRandom.test.js
+4
-0
security/cryptoFramework/js_api_test_one/src/main/js/test/SymmetricCryptography.test.js
...i_test_one/src/main/js/test/SymmetricCryptography.test.js
+92
-166
security/cryptoFramework/js_api_test_one/src/main/js/test/utils/asymmetric/publicAsymmetricCallback.js
...main/js/test/utils/asymmetric/publicAsymmetricCallback.js
+1
-72
security/cryptoFramework/js_api_test_one/src/main/js/test/utils/digestalgorithm/publicDigestPromise.js
...main/js/test/utils/digestalgorithm/publicDigestPromise.js
+2
-126
security/cryptoFramework/js_api_test_one/src/main/js/test/utils/symmetric/publicSymmetricPromise.js
...rc/main/js/test/utils/symmetric/publicSymmetricPromise.js
+0
-1
未找到文件。
security/cryptoFramework/js_api_test_one/src/main/js/test/AsymmetricCryptography.test.js
浏览文件 @
c617ad84
...
@@ -16,6 +16,7 @@
...
@@ -16,6 +16,7 @@
import
{
describe
,
beforeAll
,
afterEach
,
it
,
expect
}
from
"
@ohos/hypium
"
;
import
{
describe
,
beforeAll
,
afterEach
,
it
,
expect
}
from
"
@ohos/hypium
"
;
import
*
as
asyPromise
from
"
./utils/asymmetric/publicAsymmetricPromise
"
;
import
*
as
asyPromise
from
"
./utils/asymmetric/publicAsymmetricPromise
"
;
import
*
as
asyCallback
from
"
./utils/asymmetric/publicAsymmetricCallback
"
;
import
*
as
asyCallback
from
"
./utils/asymmetric/publicAsymmetricCallback
"
;
import
cryptoFramework
from
"
@ohos.security.cryptoFramework
"
;
export
default
function
AsymmetricCryptographyJsunit
()
{
export
default
function
AsymmetricCryptographyJsunit
()
{
describe
(
"
AsymmetricCryptographyJsunit
"
,
function
()
{
describe
(
"
AsymmetricCryptographyJsunit
"
,
function
()
{
...
@@ -398,21 +399,16 @@ export default function AsymmetricCryptographyJsunit() {
...
@@ -398,21 +399,16 @@ export default function AsymmetricCryptographyJsunit() {
"
Security_crypto_framework_ASymmetric_Encryption_RSA_1400
"
,
"
Security_crypto_framework_ASymmetric_Encryption_RSA_1400
"
,
0
,
0
,
async
function
(
done
)
{
async
function
(
done
)
{
await
asyCallback
let
rsaGenerator
=
cryptoFramework
.
createAsyKeyGenerator
(
"
RSA4096
"
);
.
encryptAndDecryptNormalProcessNull
(
let
cipherGeneratorEncrypt
=
cryptoFramework
.
createCipher
(
"
RSA4096|PKCS1
"
);
"
RSA4096
"
,
let
globalRsaKeyPair
=
rsaGenerator
.
generateKeyPair
();
"
RSA4096|PKCS1
"
try
{
)
await
cipherGeneratorEncrypt
.
init
(
cryptoFramework
.
CryptoMode
.
ENCRYPT_MODE
,
globalRsaKeyPair
,
null
);
.
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
();
expect
(
null
).
assertFail
();
});
}
catch
(
err
)
{
console
.
error
(
"
err is:
"
+
err
.
code
);
expect
(
err
.
code
).
assertEqual
(
401
);
}
done
();
done
();
}
}
);
);
...
...
security/cryptoFramework/js_api_test_one/src/main/js/test/AsymmetricCryptographySecond.test.js
浏览文件 @
c617ad84
...
@@ -87,6 +87,7 @@ export default function AsymmetricCryptographyJsSecondunit() {
...
@@ -87,6 +87,7 @@ export default function AsymmetricCryptographyJsSecondunit() {
async
function
(
done
)
{
async
function
(
done
)
{
try
{
try
{
cryptoFramework
.
createAsyKeyGenerator
(
"
RSA256
"
);
cryptoFramework
.
createAsyKeyGenerator
(
"
RSA256
"
);
expect
(
null
).
assertFail
();
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
error
(
"
err is:
"
+
err
.
code
);
console
.
error
(
"
err is:
"
+
err
.
code
);
expect
(
err
.
code
).
assertEqual
(
401
);
expect
(
err
.
code
).
assertEqual
(
401
);
...
@@ -94,6 +95,7 @@ export default function AsymmetricCryptographyJsSecondunit() {
...
@@ -94,6 +95,7 @@ export default function AsymmetricCryptographyJsSecondunit() {
try
{
try
{
cryptoFramework
.
createAsyKeyGenerator
(
"
NULL
"
);
cryptoFramework
.
createAsyKeyGenerator
(
"
NULL
"
);
expect
(
null
).
assertFail
();
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
error
(
"
err is:
"
+
err
.
code
);
console
.
error
(
"
err is:
"
+
err
.
code
);
expect
(
err
.
code
).
assertEqual
(
401
);
expect
(
err
.
code
).
assertEqual
(
401
);
...
@@ -116,24 +118,28 @@ export default function AsymmetricCryptographyJsSecondunit() {
...
@@ -116,24 +118,28 @@ export default function AsymmetricCryptographyJsSecondunit() {
let
rsaGenerator
=
cryptoFramework
.
createAsyKeyGenerator
(
"
RSA3072
"
);
let
rsaGenerator
=
cryptoFramework
.
createAsyKeyGenerator
(
"
RSA3072
"
);
await
rsaGenerator
.
generateKeyPair
();
await
rsaGenerator
.
generateKeyPair
();
cryptoFramework
.
createSign
(
"
RSA4096|NULL|SHA256
"
);
cryptoFramework
.
createSign
(
"
RSA4096|NULL|SHA256
"
);
expect
(
null
).
assertFail
();
}
catch
(
err
)
{
}
catch
(
err
)
{
expect
(
err
.
code
).
assertEqual
(
401
);
expect
(
err
.
code
).
assertEqual
(
401
);
}
}
try
{
try
{
cryptoFramework
.
createSign
(
"
RSA4096|PKCS1|NULL
"
);
cryptoFramework
.
createSign
(
"
RSA4096|PKCS1|NULL
"
);
expect
(
null
).
assertFail
();
}
catch
(
err
)
{
}
catch
(
err
)
{
expect
(
err
.
code
).
assertEqual
(
401
);
expect
(
err
.
code
).
assertEqual
(
401
);
}
}
try
{
try
{
cryptoFramework
.
createSign
(
"
RSA4096|PKCS1|SHA122
"
);
cryptoFramework
.
createSign
(
"
RSA4096|PKCS1|SHA122
"
);
expect
(
null
).
assertFail
();
}
catch
(
err
)
{
}
catch
(
err
)
{
expect
(
err
.
code
).
assertEqual
(
401
);
expect
(
err
.
code
).
assertEqual
(
401
);
}
}
try
{
try
{
cryptoFramework
.
createSign
(
"
RSA4096|PKCS5|SHA256
"
);
cryptoFramework
.
createSign
(
"
RSA4096|PKCS5|SHA256
"
);
expect
(
null
).
assertFail
();
}
catch
(
err
)
{
}
catch
(
err
)
{
expect
(
err
.
code
).
assertEqual
(
401
);
expect
(
err
.
code
).
assertEqual
(
401
);
}
}
...
@@ -213,24 +219,28 @@ export default function AsymmetricCryptographyJsSecondunit() {
...
@@ -213,24 +219,28 @@ export default function AsymmetricCryptographyJsSecondunit() {
let
rsaGenerator
=
cryptoFramework
.
createAsyKeyGenerator
(
"
RSA3072
"
);
let
rsaGenerator
=
cryptoFramework
.
createAsyKeyGenerator
(
"
RSA3072
"
);
await
rsaGenerator
.
generateKeyPair
();
await
rsaGenerator
.
generateKeyPair
();
cryptoFramework
.
createVerify
(
"
RSA4096|NULL|SHA256
"
);
cryptoFramework
.
createVerify
(
"
RSA4096|NULL|SHA256
"
);
expect
(
null
).
assertFail
();
}
catch
(
err
)
{
}
catch
(
err
)
{
expect
(
err
.
code
).
assertEqual
(
401
);
expect
(
err
.
code
).
assertEqual
(
401
);
}
}
try
{
try
{
cryptoFramework
.
createVerify
(
"
RSA4096|PKCS1|NULL
"
);
cryptoFramework
.
createVerify
(
"
RSA4096|PKCS1|NULL
"
);
expect
(
null
).
assertFail
();
}
catch
(
err
)
{
}
catch
(
err
)
{
expect
(
err
.
code
).
assertEqual
(
401
);
expect
(
err
.
code
).
assertEqual
(
401
);
}
}
try
{
try
{
cryptoFramework
.
createVerify
(
"
RSA4096|PKCS1|SHA122
"
);
cryptoFramework
.
createVerify
(
"
RSA4096|PKCS1|SHA122
"
);
expect
(
null
).
assertFail
();
}
catch
(
err
)
{
}
catch
(
err
)
{
expect
(
err
.
code
).
assertEqual
(
401
);
expect
(
err
.
code
).
assertEqual
(
401
);
}
}
try
{
try
{
cryptoFramework
.
createVerify
(
"
RSA4096|PKCS5|SHA256
"
);
cryptoFramework
.
createVerify
(
"
RSA4096|PKCS5|SHA256
"
);
expect
(
null
).
assertFail
();
}
catch
(
err
)
{
}
catch
(
err
)
{
expect
(
err
.
code
).
assertEqual
(
401
);
expect
(
err
.
code
).
assertEqual
(
401
);
}
}
...
@@ -374,6 +384,7 @@ export default function AsymmetricCryptographyJsSecondunit() {
...
@@ -374,6 +384,7 @@ export default function AsymmetricCryptographyJsSecondunit() {
async
function
(
done
)
{
async
function
(
done
)
{
try
{
try
{
cryptoFramework
.
createAsyKeyGenerator
(
"
ECC1
"
);
cryptoFramework
.
createAsyKeyGenerator
(
"
ECC1
"
);
expect
(
null
).
assertFail
();
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
error
(
"
err is:
"
+
err
.
code
);
console
.
error
(
"
err is:
"
+
err
.
code
);
expect
(
err
.
code
).
assertEqual
(
401
);
expect
(
err
.
code
).
assertEqual
(
401
);
...
@@ -381,6 +392,7 @@ export default function AsymmetricCryptographyJsSecondunit() {
...
@@ -381,6 +392,7 @@ export default function AsymmetricCryptographyJsSecondunit() {
try
{
try
{
cryptoFramework
.
createAsyKeyGenerator
(
""
);
cryptoFramework
.
createAsyKeyGenerator
(
""
);
expect
(
null
).
assertFail
();
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
error
(
"
err is:
"
+
err
.
code
);
console
.
error
(
"
err is:
"
+
err
.
code
);
expect
(
err
.
code
).
assertEqual
(
401
);
expect
(
err
.
code
).
assertEqual
(
401
);
...
@@ -403,21 +415,25 @@ export default function AsymmetricCryptographyJsSecondunit() {
...
@@ -403,21 +415,25 @@ export default function AsymmetricCryptographyJsSecondunit() {
let
rsaGenerator
=
cryptoFramework
.
createAsyKeyGenerator
(
"
ECC224
"
);
let
rsaGenerator
=
cryptoFramework
.
createAsyKeyGenerator
(
"
ECC224
"
);
await
rsaGenerator
.
generateKeyPair
();
await
rsaGenerator
.
generateKeyPair
();
cryptoFramework
.
createSign
(
"
ECC224|SHA257
"
);
cryptoFramework
.
createSign
(
"
ECC224|SHA257
"
);
expect
(
null
).
assertFail
();
}
catch
(
err
)
{
}
catch
(
err
)
{
expect
(
err
.
code
).
assertEqual
(
401
);
expect
(
err
.
code
).
assertEqual
(
401
);
}
}
try
{
try
{
cryptoFramework
.
createSign
(
"
ECC224|NULL
"
);
cryptoFramework
.
createSign
(
"
ECC224|NULL
"
);
expect
(
null
).
assertFail
();
}
catch
(
err
)
{
}
catch
(
err
)
{
expect
(
err
.
code
).
assertEqual
(
401
);
expect
(
err
.
code
).
assertEqual
(
401
);
}
}
try
{
try
{
cryptoFramework
.
createSign
(
"
NULL|SHA1
"
);
cryptoFramework
.
createSign
(
"
NULL|SHA1
"
);
expect
(
null
).
assertFail
();
}
catch
(
err
)
{
}
catch
(
err
)
{
expect
(
err
.
code
).
assertEqual
(
401
);
expect
(
err
.
code
).
assertEqual
(
401
);
}
}
try
{
try
{
cryptoFramework
.
createSign
(
"
ECC1|SHA1
"
);
cryptoFramework
.
createSign
(
"
ECC1|SHA1
"
);
expect
(
null
).
assertFail
();
}
catch
(
err
)
{
}
catch
(
err
)
{
expect
(
err
.
code
).
assertEqual
(
401
);
expect
(
err
.
code
).
assertEqual
(
401
);
}
}
...
@@ -438,21 +454,25 @@ export default function AsymmetricCryptographyJsSecondunit() {
...
@@ -438,21 +454,25 @@ export default function AsymmetricCryptographyJsSecondunit() {
try
{
try
{
cryptoFramework
.
createAsyKeyGenerator
(
"
RSA3072
"
);
cryptoFramework
.
createAsyKeyGenerator
(
"
RSA3072
"
);
cryptoFramework
.
createVerify
(
"
ECC1|SHA256
"
);
cryptoFramework
.
createVerify
(
"
ECC1|SHA256
"
);
expect
(
null
).
assertFail
();
}
catch
(
err
)
{
}
catch
(
err
)
{
expect
(
err
.
code
).
assertEqual
(
401
);
expect
(
err
.
code
).
assertEqual
(
401
);
}
}
try
{
try
{
cryptoFramework
.
createVerify
(
"
NULL|SHA256
"
);
cryptoFramework
.
createVerify
(
"
NULL|SHA256
"
);
expect
(
null
).
assertFail
();
}
catch
(
err
)
{
}
catch
(
err
)
{
expect
(
err
.
code
).
assertEqual
(
401
);
expect
(
err
.
code
).
assertEqual
(
401
);
}
}
try
{
try
{
cryptoFramework
.
createVerify
(
"
ECC224|SHA122
"
);
cryptoFramework
.
createVerify
(
"
ECC224|SHA122
"
);
expect
(
null
).
assertFail
();
}
catch
(
err
)
{
}
catch
(
err
)
{
expect
(
err
.
code
).
assertEqual
(
401
);
expect
(
err
.
code
).
assertEqual
(
401
);
}
}
try
{
try
{
cryptoFramework
.
createVerify
(
"
ECC224|NULL
"
);
cryptoFramework
.
createVerify
(
"
ECC224|NULL
"
);
expect
(
null
).
assertFail
();
}
catch
(
err
)
{
}
catch
(
err
)
{
expect
(
err
.
code
).
assertEqual
(
401
);
expect
(
err
.
code
).
assertEqual
(
401
);
}
}
...
@@ -600,12 +620,14 @@ export default function AsymmetricCryptographyJsSecondunit() {
...
@@ -600,12 +620,14 @@ export default function AsymmetricCryptographyJsSecondunit() {
async
function
(
done
)
{
async
function
(
done
)
{
try
{
try
{
cryptoFramework
.
createKeyAgreement
(
"
ECC5
"
);
cryptoFramework
.
createKeyAgreement
(
"
ECC5
"
);
expect
(
null
).
assertFail
();
}
catch
(
err
)
{
}
catch
(
err
)
{
expect
(
err
.
code
).
assertEqual
(
401
);
expect
(
err
.
code
).
assertEqual
(
401
);
}
}
try
{
try
{
cryptoFramework
.
createKeyAgreement
(
null
);
cryptoFramework
.
createKeyAgreement
(
null
);
expect
(
null
).
assertFail
();
}
catch
(
err
)
{
}
catch
(
err
)
{
expect
(
err
.
code
).
assertEqual
(
401
);
expect
(
err
.
code
).
assertEqual
(
401
);
}
}
...
@@ -638,6 +660,7 @@ export default function AsymmetricCryptographyJsSecondunit() {
...
@@ -638,6 +660,7 @@ export default function AsymmetricCryptographyJsSecondunit() {
let
keyAgrementGenerator
=
cryptoFramework
.
createKeyAgreement
(
"
ECC256
"
);
let
keyAgrementGenerator
=
cryptoFramework
.
createKeyAgreement
(
"
ECC256
"
);
try
{
try
{
await
keyAgrementGenerator
.
generateSecret
(
null
,
null
);
await
keyAgrementGenerator
.
generateSecret
(
null
,
null
);
expect
(
null
).
assertFail
();
}
catch
(
err
)
{
}
catch
(
err
)
{
expect
(
err
.
code
).
assertEqual
(
401
);
expect
(
err
.
code
).
assertEqual
(
401
);
}
}
...
@@ -656,6 +679,7 @@ export default function AsymmetricCryptographyJsSecondunit() {
...
@@ -656,6 +679,7 @@ export default function AsymmetricCryptographyJsSecondunit() {
}
}
try
{
try
{
await
keyAgrementGenerator
.
generateSecret
(
null
,
keyPair2
.
pubKey
)
await
keyAgrementGenerator
.
generateSecret
(
null
,
keyPair2
.
pubKey
)
expect
(
null
).
assertFail
();
}
catch
(
err
)
{
}
catch
(
err
)
{
expect
(
err
.
code
).
assertEqual
(
401
);
expect
(
err
.
code
).
assertEqual
(
401
);
}
}
...
@@ -688,6 +712,7 @@ export default function AsymmetricCryptographyJsSecondunit() {
...
@@ -688,6 +712,7 @@ export default function AsymmetricCryptographyJsSecondunit() {
let
keyAgrementGenerator
=
cryptoFramework
.
createKeyAgreement
(
"
ECC521
"
);
let
keyAgrementGenerator
=
cryptoFramework
.
createKeyAgreement
(
"
ECC521
"
);
try
{
try
{
await
keyAgrementGenerator
.
generateSecret
(
keyPair1
.
prikey
,
keyPair2
.
pubKey
)
await
keyAgrementGenerator
.
generateSecret
(
keyPair1
.
prikey
,
keyPair2
.
pubKey
)
expect
(
null
).
assertFail
();
}
catch
(
err
)
{
}
catch
(
err
)
{
expect
(
err
.
code
).
assertEqual
(
401
);
expect
(
err
.
code
).
assertEqual
(
401
);
}
}
...
...
security/cryptoFramework/js_api_test_one/src/main/js/test/DigestAlgorithm.test.js
浏览文件 @
c617ad84
...
@@ -17,9 +17,6 @@ import { describe, beforeAll, afterEach, it, expect } from "@ohos/hypium";
...
@@ -17,9 +17,6 @@ import { describe, beforeAll, afterEach, it, expect } from "@ohos/hypium";
import
{
import
{
testHMACDigestPromise
,
testHMACDigestPromise
,
testMDDigestPromise
,
testMDDigestPromise
,
testHMACErrorAlgorithm
,
testHMACDigestPromiseErrorKey
,
testHMACDigestPromiseDatablobNull
,
testHMACDigestPromiseDatablobLong
,
testHMACDigestPromiseDatablobLong
,
}
from
"
./utils/digestalgorithm/publicDigestPromise
"
;
}
from
"
./utils/digestalgorithm/publicDigestPromise
"
;
import
{
import
{
...
@@ -29,6 +26,11 @@ import {
...
@@ -29,6 +26,11 @@ import {
testMDErrorAlgorithmNull
,
testMDErrorAlgorithmNull
,
testMDDigestCallbackLen
,
testMDDigestCallbackLen
,
}
from
"
./utils/digestalgorithm/publicDigestCallback
"
;
}
from
"
./utils/digestalgorithm/publicDigestCallback
"
;
import
{
stringTouInt8Array
,
uInt8ArrayToShowStr
,
uInt8ArrayToString
,
}
from
"
./utils/common/publicDoString
"
;
import
cryptoFramework
from
"
@ohos.security.cryptoFramework
"
;
import
cryptoFramework
from
"
@ohos.security.cryptoFramework
"
;
...
@@ -202,18 +204,21 @@ export default function DigestAlgorithmJsunit() {
...
@@ -202,18 +204,21 @@ export default function DigestAlgorithmJsunit() {
}
}
})
})
})
})
expect
(
null
).
assertFail
();
}
catch
(
err
)
{
}
catch
(
err
)
{
expect
(
err
.
code
).
assertEqual
(
401
);
expect
(
err
.
code
).
assertEqual
(
401
);
}
}
try
{
try
{
await
mdGenerator
.
update
(
0
);
await
mdGenerator
.
update
(
0
);
expect
(
null
).
assertFail
();
}
catch
(
err
)
{
}
catch
(
err
)
{
expect
(
err
.
code
).
assertEqual
(
401
);
expect
(
err
.
code
).
assertEqual
(
401
);
}
}
try
{
try
{
await
mdGenerator
.
digest
();
await
mdGenerator
.
digest
();
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
error
(
"
1111111
"
+
err
.
code
);
console
.
error
(
"
err is
"
+
err
.
code
);
expect
(
err
.
code
).
assertEqual
(
401
)
}
}
done
();
done
();
});
});
...
@@ -304,13 +309,20 @@ export default function DigestAlgorithmJsunit() {
...
@@ -304,13 +309,20 @@ export default function DigestAlgorithmJsunit() {
* @tc.desc Use the Promise Style of Interface
* @tc.desc Use the Promise Style of Interface
*/
*/
it
(
"
Security_crypto_framework_HMAC_0600
"
,
0
,
async
function
(
done
)
{
it
(
"
Security_crypto_framework_HMAC_0600
"
,
0
,
async
function
(
done
)
{
await
testHMACErrorAlgorithm
(
"
SHA5
"
,
null
)
try
{
.
then
((
data
)
=>
{
cryptoFramework
.
createMac
(
"
SHA5
"
);
expect
(
data
==
null
).
assertTrue
();
})
.
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
expect
(
null
).
assertFail
();
});
}
catch
(
err
)
{
console
.
error
(
"
[Promise]: error code:
"
+
err
.
code
+
"
, message is:
"
+
err
.
message
);
expect
(
err
.
code
).
assertEqual
(
801
);
}
try
{
cryptoFramework
.
createMac
(
null
);
expect
(
null
).
assertFail
();
}
catch
(
err
)
{
console
.
error
(
"
[Promise]: error code:
"
+
err
.
code
+
"
, message is:
"
+
err
.
message
);
expect
(
err
.
code
).
assertEqual
(
401
);
}
done
();
done
();
});
});
...
@@ -320,13 +332,23 @@ export default function DigestAlgorithmJsunit() {
...
@@ -320,13 +332,23 @@ export default function DigestAlgorithmJsunit() {
* @tc.desc Use the Promise Style of Interface
* @tc.desc Use the Promise Style of Interface
*/
*/
it
(
"
Security_crypto_framework_HMAC_0700
"
,
0
,
async
function
(
done
)
{
it
(
"
Security_crypto_framework_HMAC_0700
"
,
0
,
async
function
(
done
)
{
await
testHMACDigestPromiseErrorKey
(
"
SHA512
"
,
"
RSA1024|PRIMES_2
"
)
let
globalHMAC
=
cryptoFramework
.
createMac
(
"
SHA512
"
);
.
then
((
data
)
=>
{
let
globalsymKeyGenerator
=
cryptoFramework
.
createAsyKeyGenerator
(
"
RSA1024|PRIMES_2
"
);
expect
(
data
==
null
).
assertTrue
();
let
key
=
globalsymKeyGenerator
.
generateKeyPair
();
})
try
{
.
catch
((
err
)
=>
{
await
globalHMAC
.
init
(
key
);
expect
(
null
).
assertFail
();
expect
(
null
).
assertFail
();
});
}
catch
(
err
)
{
console
.
error
(
"
[Promise]init(key): error code:
"
+
err
.
code
+
"
, message is:
"
+
err
.
message
);
expect
(
err
.
code
).
assertEqual
(
401
);
};
try
{
await
globalHMAC
.
init
(
null
);
expect
(
null
).
assertFail
();
}
catch
(
err
)
{
console
.
error
(
"
[Promise]init(null): error code:
"
+
err
.
code
+
"
, message is:
"
+
err
.
message
);
expect
(
err
.
code
).
assertEqual
(
401
);
};
done
();
done
();
});
});
...
@@ -336,13 +358,17 @@ export default function DigestAlgorithmJsunit() {
...
@@ -336,13 +358,17 @@ export default function DigestAlgorithmJsunit() {
* @tc.desc Use the Promise Style of Interface
* @tc.desc Use the Promise Style of Interface
*/
*/
it
(
"
Security_crypto_framework_HMAC_0800
"
,
0
,
async
function
(
done
)
{
it
(
"
Security_crypto_framework_HMAC_0800
"
,
0
,
async
function
(
done
)
{
await
testHMACDigestPromiseDatablobNull
(
"
SHA512
"
,
"
3DES192
"
)
let
globalHMAC
=
cryptoFramework
.
createMac
(
"
SHA512
"
);
.
then
((
data
)
=>
{
let
globalsymKeyGenerator
=
cryptoFramework
.
createSymKeyGenerator
(
"
3DES192
"
);
expect
(
data
==
null
).
assertTrue
();
let
key
=
await
globalsymKeyGenerator
.
generateSymKey
();
})
await
globalHMAC
.
init
(
key
);
.
catch
((
err
)
=>
{
try
{
await
globalHMAC
.
update
(
null
);
expect
(
null
).
assertFail
();
expect
(
null
).
assertFail
();
});
}
catch
(
err
)
{
console
.
error
(
"
[Promise]init(null): error code:
"
+
err
.
code
+
"
, message is:
"
+
err
.
message
);
expect
(
err
.
code
).
assertEqual
(
401
);
}
done
();
done
();
});
});
...
...
security/cryptoFramework/js_api_test_one/src/main/js/test/SecurityRandom.test.js
浏览文件 @
c617ad84
...
@@ -82,6 +82,7 @@ export default function SecurityRandomJsunit() {
...
@@ -82,6 +82,7 @@ export default function SecurityRandomJsunit() {
}
}
try
{
try
{
await
randomGenerator
.
generateRandom
(
null
);
await
randomGenerator
.
generateRandom
(
null
);
expect
(
null
).
assertFail
();
}
catch
(
err
)
{
}
catch
(
err
)
{
expect
(
err
.
code
).
assertEqual
(
401
);
expect
(
err
.
code
).
assertEqual
(
401
);
}
}
...
@@ -100,6 +101,7 @@ export default function SecurityRandomJsunit() {
...
@@ -100,6 +101,7 @@ export default function SecurityRandomJsunit() {
}
}
try
{
try
{
await
randomGenerator
.
generateRandom
(
2147483648
);
await
randomGenerator
.
generateRandom
(
2147483648
);
expect
(
null
).
assertFail
();
}
catch
(
err
)
{
}
catch
(
err
)
{
expect
(
err
.
code
).
assertEqual
(
401
);
expect
(
err
.
code
).
assertEqual
(
401
);
}
}
...
@@ -115,11 +117,13 @@ export default function SecurityRandomJsunit() {
...
@@ -115,11 +117,13 @@ export default function SecurityRandomJsunit() {
let
randomGenerator
=
cryptoFramework
.
createRandom
();
let
randomGenerator
=
cryptoFramework
.
createRandom
();
try
{
try
{
randomGenerator
.
setSeed
(
null
);
randomGenerator
.
setSeed
(
null
);
expect
(
null
).
assertFail
();
}
catch
(
err
)
{
}
catch
(
err
)
{
expect
(
err
.
code
).
assertEqual
(
401
);
expect
(
err
.
code
).
assertEqual
(
401
);
}
}
try
{
try
{
randomGenerator
.
setSeed
(
0
);
randomGenerator
.
setSeed
(
0
);
expect
(
null
).
assertFail
();
}
catch
(
err
)
{
}
catch
(
err
)
{
expect
(
err
.
code
).
assertEqual
(
401
);
expect
(
err
.
code
).
assertEqual
(
401
);
}
}
...
...
security/cryptoFramework/js_api_test_one/src/main/js/test/SymmetricCryptography.test.js
浏览文件 @
c617ad84
...
@@ -16,6 +16,8 @@
...
@@ -16,6 +16,8 @@
import
{
describe
,
beforeAll
,
afterEach
,
it
,
expect
}
from
"
@ohos/hypium
"
;
import
{
describe
,
beforeAll
,
afterEach
,
it
,
expect
}
from
"
@ohos/hypium
"
;
import
*
as
symPromise
from
"
./utils/symmetric/publicSymmetricPromise
"
;
import
*
as
symPromise
from
"
./utils/symmetric/publicSymmetricPromise
"
;
import
*
as
symCallback
from
"
./utils/symmetric/publicSymmetricCallback
"
;
import
*
as
symCallback
from
"
./utils/symmetric/publicSymmetricCallback
"
;
import
*
as
publicModule
from
"
./utils/common/publicDoString
"
;
import
cryptoFramework
from
"
@ohos.security.cryptoFramework
"
;
export
default
function
SymmetricCryptographyJsunit
()
{
export
default
function
SymmetricCryptographyJsunit
()
{
describe
(
"
SymmetricCryptographyJsunit
"
,
function
()
{
describe
(
"
SymmetricCryptographyJsunit
"
,
function
()
{
...
@@ -382,34 +384,20 @@ export default function SymmetricCryptographyJsunit() {
...
@@ -382,34 +384,20 @@ export default function SymmetricCryptographyJsunit() {
"
Security_crypto_framework_Symmetric_Encryption_AES_1300
"
,
"
Security_crypto_framework_Symmetric_Encryption_AES_1300
"
,
0
,
0
,
async
function
(
done
)
{
async
function
(
done
)
{
await
symPromise
try
{
.
createSymKeyGeneratorFail
(
cryptoFramework
.
createSymKeyGenerator
(
"
AES257
"
);
"
AES257
"
,
)
.
then
((
data
)
=>
{
expect
(
data
==
"
Error: create C generator fail.
"
).
assertTrue
();
})
.
catch
((
err
)
=>
{
console
.
error
(
"
Security_crypto_framework_Symmetric_Encryption_AES_1300 catch error:
"
+
err
);
expect
(
null
).
assertFail
();
expect
(
null
).
assertFail
();
});
}
catch
(
err
)
{
await
symPromise
console
.
error
(
"
err is :
"
+
err
.
code
);
.
createSymKeyGeneratorFail
(
expect
(
err
.
code
).
assertEqual
(
801
);
"
AESNULL
"
,
}
)
try
{
.
then
((
data
)
=>
{
cryptoFramework
.
createSymKeyGenerator
(
"
AESNULL
"
);
expect
(
data
==
"
Error: create C generator fail.
"
).
assertTrue
();
})
.
catch
((
err
)
=>
{
console
.
error
(
"
Security_crypto_framework_Symmetric_Encryption_AES_1300 catch error:
"
+
err
);
expect
(
null
).
assertFail
();
expect
(
null
).
assertFail
();
});
}
catch
(
err
)
{
console
.
error
(
"
err is :
"
+
err
.
code
);
expect
(
err
.
code
).
assertEqual
(
801
);
}
done
();
done
();
}
}
);
);
...
@@ -423,34 +411,20 @@ export default function SymmetricCryptographyJsunit() {
...
@@ -423,34 +411,20 @@ export default function SymmetricCryptographyJsunit() {
"
Security_crypto_framework_Symmetric_Encryption_AES_1400
"
,
"
Security_crypto_framework_Symmetric_Encryption_AES_1400
"
,
0
,
0
,
async
function
(
done
)
{
async
function
(
done
)
{
await
symPromise
try
{
.
createSymCipherFail
(
cryptoFramework
.
createCipher
(
"
AES128|NULL|PKCS7
"
);
"
AES128|NULL|PKCS7
"
,
)
.
then
((
data
)
=>
{
expect
(
data
==
"
Error: create C cipher fail!
"
).
assertTrue
();
})
.
catch
((
err
)
=>
{
console
.
error
(
"
Security_crypto_framework_Symmetric_Encryption_AES_1400 catch error:
"
+
err
);
expect
(
null
).
assertFail
();
expect
(
null
).
assertFail
();
});
}
catch
(
err
)
{
await
symPromise
console
.
error
(
"
err is :
"
+
err
.
code
);
.
createSymCipherFail
(
expect
(
err
.
code
).
assertEqual
(
801
);
"
AES128|ADF|PKCS7
"
,
}
)
try
{
.
then
((
data
)
=>
{
cryptoFramework
.
createCipher
(
"
AES128|ADF|PKCS7
"
);
expect
(
data
==
"
Error: create C cipher fail!
"
).
assertTrue
();
})
.
catch
((
err
)
=>
{
console
.
error
(
"
Security_crypto_framework_Symmetric_Encryption_AES_1400 catch error:
"
+
err
);
expect
(
null
).
assertFail
();
expect
(
null
).
assertFail
();
});
}
catch
(
err
)
{
console
.
error
(
"
err is :
"
+
err
.
code
);
expect
(
err
.
code
).
assertEqual
(
801
);
}
done
();
done
();
}
}
);
);
...
@@ -464,34 +438,20 @@ export default function SymmetricCryptographyJsunit() {
...
@@ -464,34 +438,20 @@ export default function SymmetricCryptographyJsunit() {
"
Security_crypto_framework_Symmetric_Encryption_AES_1500
"
,
"
Security_crypto_framework_Symmetric_Encryption_AES_1500
"
,
0
,
0
,
async
function
(
done
)
{
async
function
(
done
)
{
await
symPromise
try
{
.
createSymCipherFail
(
cryptoFramework
.
createCipher
(
"
AES128|GCM|NULL
"
);
"
AES128|GCM|NULL
"
,
)
.
then
((
data
)
=>
{
expect
(
data
==
"
Error: create C cipher fail!
"
).
assertTrue
();
})
.
catch
((
err
)
=>
{
console
.
error
(
"
Security_crypto_framework_Symmetric_Encryption_AES_1500 catch error:
"
+
err
);
expect
(
null
).
assertFail
();
expect
(
null
).
assertFail
();
});
}
catch
(
err
)
{
await
symPromise
console
.
error
(
"
err is :
"
+
err
.
code
);
.
createSymCipherFail
(
expect
(
err
.
code
).
assertEqual
(
801
);
"
AES128|GCM|CCCC
"
,
}
)
try
{
.
then
((
data
)
=>
{
cryptoFramework
.
createCipher
(
"
AES128|GCM|CCCC
"
);
expect
(
data
==
"
Error: create C cipher fail!
"
).
assertTrue
();
})
.
catch
((
err
)
=>
{
console
.
error
(
"
Security_crypto_framework_Symmetric_Encryption_AES_1500 catch error:
"
+
err
);
expect
(
null
).
assertFail
();
expect
(
null
).
assertFail
();
});
}
catch
(
err
)
{
console
.
error
(
"
err is :
"
+
err
.
code
);
expect
(
err
.
code
).
assertEqual
(
801
);
}
done
();
done
();
}
}
);
);
...
@@ -662,9 +622,9 @@ export default function SymmetricCryptographyJsunit() {
...
@@ -662,9 +622,9 @@ export default function SymmetricCryptographyJsunit() {
.
catch
((
err
)
=>
{
.
catch
((
err
)
=>
{
console
.
error
(
console
.
error
(
"
Security_crypto_framework_Symmetric_Encryption_3DES_0600 catch error:
"
+
"
Security_crypto_framework_Symmetric_Encryption_3DES_0600 catch error:
"
+
err
err
.
code
);
);
expect
(
err
==
"
Error: doFinal failed.
"
).
assertTrue
(
);
expect
(
err
.
code
).
assertEqual
(
17630001
);
});
});
done
();
done
();
}
}
...
@@ -679,38 +639,22 @@ export default function SymmetricCryptographyJsunit() {
...
@@ -679,38 +639,22 @@ export default function SymmetricCryptographyJsunit() {
"
Security_crypto_framework_Symmetric_Encryption_3DES_0700
"
,
"
Security_crypto_framework_Symmetric_Encryption_3DES_0700
"
,
0
,
0
,
async
function
(
done
)
{
async
function
(
done
)
{
await
symPromise
try
{
.
encryptAndDecryptNormalProcess
(
let
symKeyGenerator
=
cryptoFramework
.
createSymKeyGenerator
(
"
3DES192
"
);
"
3DES192
"
,
expect
(
symKeyGenerator
!=
null
).
assertTrue
();
"
3DES192|null|PKCS7
"
,
let
SymKey
=
await
symKeyGenerator
.
generateSymKey
();
"
genIvParamsSpec
"
expect
(
SymKey
!=
null
).
assertTrue
();
)
cryptoFramework
.
createCipher
(
"
3DES192|null|PKCS7
"
);
.
then
((
data
)
=>
{
expect
(
null
).
assertFail
();
expect
(
data
==
"
Error: create C cipher fail!
"
).
assertTrue
();
}
catch
(
err
)
{
})
expect
(
err
.
code
).
assertEqual
(
801
);
.
catch
((
err
)
=>
{
}
console
.
error
(
try
{
"
Security_crypto_framework_Symmetric_Encryption_3DES_0700 catch error:
"
+
cryptoFramework
.
createCipher
(
"
3DES192|DDD|PKCS7
"
);
err
expect
(
null
).
assertFail
();
);
}
catch
(
err
)
{
expect
(
null
).
assertTrue
();
expect
(
err
.
code
).
assertEqual
(
801
);
});
}
await
symPromise
.
encryptAndDecryptNormalProcess
(
"
3DES192
"
,
"
3DES192|DDD|PKCS7
"
,
"
genIvParamsSpec
"
)
.
then
((
data
)
=>
{
expect
(
data
==
"
Error: create C cipher fail!
"
).
assertTrue
();
})
.
catch
((
err
)
=>
{
console
.
error
(
"
Security_crypto_framework_Symmetric_Encryption_3DES_0700 catch error:
"
+
err
);
expect
(
null
).
assertTrue
();
});
done
();
done
();
}
}
);
);
...
@@ -724,38 +668,22 @@ export default function SymmetricCryptographyJsunit() {
...
@@ -724,38 +668,22 @@ export default function SymmetricCryptographyJsunit() {
"
Security_crypto_framework_Symmetric_Encryption_3DES_0800
"
,
"
Security_crypto_framework_Symmetric_Encryption_3DES_0800
"
,
0
,
0
,
async
function
(
done
)
{
async
function
(
done
)
{
await
symPromise
try
{
.
encryptAndDecryptNormalProcess
(
let
symKeyGenerator
=
cryptoFramework
.
createSymKeyGenerator
(
"
3DES192
"
);
"
3DES192
"
,
expect
(
symKeyGenerator
!=
null
).
assertTrue
();
"
3DES192|ECB|null
"
,
let
SymKey
=
await
symKeyGenerator
.
generateSymKey
();
"
genIvParamsSpec
"
expect
(
SymKey
!=
null
).
assertTrue
();
)
cryptoFramework
.
createCipher
(
"
3DES192|ECB|null
"
);
.
then
((
data
)
=>
{
expect
(
null
).
assertFail
();
expect
(
data
==
"
Error: create C cipher fail!
"
).
assertTrue
();
}
catch
(
err
)
{
})
expect
(
err
.
code
).
assertEqual
(
801
);
.
catch
((
err
)
=>
{
}
console
.
error
(
try
{
"
Security_crypto_framework_Symmetric_Encryption_3DES_0800 catch error:
"
+
cryptoFramework
.
createCipher
(
"
3DES192|ECB|CCCCC
"
);
err
expect
(
null
).
assertFail
();
);
}
catch
(
err
)
{
expect
(
null
).
assertTrue
();
expect
(
err
.
code
).
assertEqual
(
801
);
});
}
await
symPromise
.
encryptAndDecryptNormalProcess
(
"
3DES192
"
,
"
3DES192|ECB|CCCCC
"
,
"
genIvParamsSpec
"
)
.
then
((
data
)
=>
{
expect
(
data
==
"
Error: create C cipher fail!
"
).
assertTrue
();
})
.
catch
((
err
)
=>
{
console
.
error
(
"
Security_crypto_framework_Symmetric_Encryption_3DES_0800 catch error:
"
+
err
);
expect
(
null
).
assertTrue
();
});
done
();
done
();
}
}
);
);
...
@@ -798,22 +726,20 @@ export default function SymmetricCryptographyJsunit() {
...
@@ -798,22 +726,20 @@ export default function SymmetricCryptographyJsunit() {
"
Security_crypto_framework_Symmetric_Encryption_AES_3000
"
,
"
Security_crypto_framework_Symmetric_Encryption_AES_3000
"
,
0
,
0
,
async
function
(
done
)
{
async
function
(
done
)
{
await
symPromise
let
symKeyGenerator
=
cryptoFramework
.
createSymKeyGenerator
(
"
AES256
"
);
.
encryptAndDecryptNormalProcessSpecialdata
(
expect
(
symKeyGenerator
!=
null
).
assertTrue
();
"
AES256
"
,
let
symKey
=
await
symKeyGenerator
.
generateSymKey
();
"
AES256|CCM|PKCS7
"
,
expect
(
symKey
!=
null
).
assertTrue
();
"
genCcmParamsSpec
"
let
cipherGenerator
=
cryptoFramework
.
createCipher
(
"
AES256|CCM|PKCS7
"
);
)
expect
(
cipherGenerator
!=
null
).
assertTrue
();
.
then
((
data
)
=>
{
await
cipherGenerator
.
init
(
cryptoFramework
.
CryptoMode
.
ENCRYPT_MODE
,
symKey
,
publicModule
.
genCcmParamsSpec
());
expect
(
data
==
"
TypeError: Cannot read property length of null
"
).
assertTrue
();
try
{
})
await
cipherGenerator
.
update
(
null
);
.
catch
((
err
)
=>
{
console
.
error
(
"
Security_crypto_framework_Symmetric_Encryption_AES_3000 catch error:
"
+
err
);
expect
(
null
).
assertFail
();
expect
(
null
).
assertFail
();
});
}
catch
(
err
)
{
console
.
error
(
"
Security_crypto_framework_Symmetric_Encryption_AES_3000 catch error:
"
+
err
.
code
);
expect
(
err
.
code
).
assertEqual
(
401
);
}
done
();
done
();
}
}
);
);
...
...
security/cryptoFramework/js_api_test_one/src/main/js/test/utils/asymmetric/publicAsymmetricCallback.js
浏览文件 @
c617ad84
...
@@ -551,82 +551,11 @@ async function signAndVerifyNormalProcessSuperdata(asyAlgoName, signVerifyAlgoNa
...
@@ -551,82 +551,11 @@ async function signAndVerifyNormalProcessSuperdata(asyAlgoName, signVerifyAlgoNa
});
});
}
}
async
function
encryptAndDecryptNormalProcessNull
(
asyAlgoName
,
cipherAlgoName
)
{
var
globalCipherText
;
var
globalRsaKeyPair
;
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
();
globalRsaKeyPair
=
rsaKeyPair
;
return
initCipher
(
cipherGeneratorEncrypt
,
encryptMode
,
globalRsaKeyPair
.
pubKey
,
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
,
globalRsaKeyPair
.
priKey
,
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
);
reject
();
})
.
catch
((
err
)
=>
{
console
.
error
(
"
[Callback] encryptAndDecryptNormalProcess catch err:
"
+
err
);
resolve
(
err
);
});
});
}
export
{
export
{
encryptAndDecryptNormalProcess
,
encryptAndDecryptNormalProcess
,
signAndVerifyNormalProcess
,
signAndVerifyNormalProcess
,
convertKeyEncryptAndDecryptProcess
,
convertKeyEncryptAndDecryptProcess
,
keyAgreementProcess
,
keyAgreementProcess
,
encryptAndDecryptNormalProcessSuperdata
,
encryptAndDecryptNormalProcessSuperdata
,
signAndVerifyNormalProcessSuperdata
,
signAndVerifyNormalProcessSuperdata
encryptAndDecryptNormalProcessNull
};
};
security/cryptoFramework/js_api_test_one/src/main/js/test/utils/digestalgorithm/publicDigestPromise.js
浏览文件 @
c617ad84
...
@@ -111,130 +111,6 @@ async function testHMACDigestPromise(HMACAlgoName, keyAlgoName) {
...
@@ -111,130 +111,6 @@ async function testHMACDigestPromise(HMACAlgoName, keyAlgoName) {
});
});
}
}
async
function
testHMACErrorAlgorithm
(
HMACAlgoName1
,
HMACAlgoName2
)
{
var
globalHMAC
;
var
globalText
=
"
my test data
"
;
var
inBlob
=
{
data
:
stringTouInt8Array
(
globalText
),
};
return
new
Promise
((
resolve
,
reject
)
=>
{
try
{
globalHMAC
=
cryptoFramework
.
createMac
(
HMACAlgoName1
);
reject
();
}
catch
(
error
)
{
console
.
error
(
"
[Promise]: error code1:
"
+
error
.
code
+
"
, message is:
"
+
error
.
message
);
expect
(
error
.
code
==
801
).
assertTrue
();
}
try
{
globalHMAC
=
cryptoFramework
.
createMac
(
HMACAlgoName2
);
reject
();
}
catch
(
error
)
{
console
.
error
(
"
[Promise]: error code2:
"
+
error
.
code
+
"
, message is:
"
+
error
.
message
);
expect
(
error
.
code
==
401
).
assertTrue
();
resolve
();
}
});
}
async
function
testHMACDigestPromiseErrorKey
(
HMACAlgoName
,
keyAlgoName
)
{
var
globalHMAC
;
var
globalText
=
"
my test data
"
;
let
globalsymKeyGenerator
;
var
inBlob
=
{
data
:
stringTouInt8Array
(
globalText
),
};
return
new
Promise
((
resolve
,
reject
)
=>
{
globalHMAC
=
cryptoFramework
.
createMac
(
HMACAlgoName
);
expect
(
globalHMAC
!=
null
).
assertTrue
();
console
.
warn
(
"
mac=
"
+
globalHMAC
);
console
.
warn
(
"
HMAC algName is:
"
+
globalHMAC
.
algName
);
console
.
log
(
"
start to call createSymKeyGenerator()
"
);
try
{
globalsymKeyGenerator
=
cryptoFramework
.
createAsyKeyGenerator
(
keyAlgoName
);
}
catch
(
error
)
{
console
.
error
(
"
[Promise]: error code1:
"
+
error
.
code
+
"
, message is:
"
+
error
.
message
);
}
console
.
warn
(
"
symKeyGenerator algName:
"
+
globalsymKeyGenerator
.
algName
);
expect
(
globalsymKeyGenerator
!=
null
).
assertTrue
();
console
.
log
(
"
createSymKeyGenerator ok
"
);
let
key
=
globalsymKeyGenerator
.
generateKeyPair
();
try
{
var
promiseMacInit
=
globalHMAC
.
init
(
key
);
expect
(
promiseMacInit
==
null
).
assertTrue
();
reject
();
}
catch
(
error
)
{
console
.
error
(
"
[Promise]init(key): error code:
"
+
error
.
code
+
"
, message is:
"
+
error
.
message
);
expect
(
error
.
code
==
401
).
assertTrue
();
resolve
();
};
try
{
var
promiseMacInit
=
globalHMAC
.
init
(
null
);
expect
(
promiseMacInit
==
null
).
assertTrue
();
reject
();
}
catch
(
error
)
{
console
.
error
(
"
[Promise]init(null): error code:
"
+
error
.
code
+
"
, message is:
"
+
error
.
message
);
expect
(
error
.
code
==
401
).
assertTrue
();
resolve
();
};
});
}
async
function
testHMACDigestPromiseDatablobNull
(
HMACAlgoName
,
keyAlgoName
)
{
var
globalHMAC
;
var
globalText
=
"
my test data
"
;
var
globalsymKeyGenerator
;
var
inBlob
=
{
data
:
stringTouInt8Array
(
globalText
),
};
return
new
Promise
((
resolve
,
reject
)
=>
{
globalHMAC
=
cryptoFramework
.
createMac
(
HMACAlgoName
);
expect
(
globalHMAC
!=
null
).
assertTrue
();
console
.
warn
(
"
mac=
"
+
globalHMAC
);
console
.
warn
(
"
HMAC algName is:
"
+
globalHMAC
.
algName
);
console
.
log
(
"
start to call createSymKeyGenerator()
"
);
globalsymKeyGenerator
=
cryptoFramework
.
createSymKeyGenerator
(
keyAlgoName
);
console
.
warn
(
"
symKeyGenerator algName:
"
+
globalsymKeyGenerator
.
algName
);
expect
(
globalsymKeyGenerator
!=
null
).
assertTrue
();
console
.
log
(
"
createSymKeyGenerator ok
"
);
console
.
warn
(
"
symKeyGenerator algName:
"
+
globalsymKeyGenerator
.
algName
);
globalsymKeyGenerator
.
generateSymKey
()
.
then
((
key
)
=>
{
expect
(
key
!=
null
).
assertTrue
();
console
.
warn
(
"
generateSymKey ok
"
);
console
.
warn
(
"
key algName:
"
+
key
.
algName
);
console
.
warn
(
"
key format:
"
+
key
.
format
);
var
encodedKey
=
key
.
getEncoded
();
console
.
warn
(
"
key getEncoded hex:
"
+
uInt8ArrayToShowStr
(
encodedKey
.
data
)
);
var
promiseMacInit
=
globalHMAC
.
init
(
key
);
return
promiseMacInit
;
})
.
then
(()
=>
{
try
{
var
promiseMacUpdate
=
globalHMAC
.
update
(
null
);
console
.
warn
(
"
promiseMacUpdate:
"
+
promiseMacUpdate
);
}
catch
(
error
)
{
console
.
error
(
"
[Promise]: error code:
"
+
error
.
code
+
"
, message is:
"
+
error
.
message
);
expect
(
error
.
code
==
401
).
assertTrue
();
resolve
();
}
})
.
then
(()
=>
{
var
promiseMacdoFinal
=
globalHMAC
.
doFinal
();
return
promiseMacdoFinal
;
})
.
catch
((
err
)
=>
{
console
.
error
(
"
[promise]catch err:
"
+
err
);
reject
(
err
);
});
});
}
async
function
testHMACDigestPromiseDatablobLong
(
HMACAlgoName
,
keyAlgoName
,
DatablobLen
)
{
async
function
testHMACDigestPromiseDatablobLong
(
HMACAlgoName
,
keyAlgoName
,
DatablobLen
)
{
var
globalHMAC
;
var
globalHMAC
;
var
globalsymKeyGenerator
;
var
globalsymKeyGenerator
;
...
@@ -293,5 +169,5 @@ async function testHMACDigestPromiseDatablobLong(HMACAlgoName, keyAlgoName, Data
...
@@ -293,5 +169,5 @@ async function testHMACDigestPromiseDatablobLong(HMACAlgoName, keyAlgoName, Data
});
});
});
});
}
}
export
{
testMDDigestPromise
,
testHMACDigestPromise
,
testHMACErrorAlgorithm
,
testHMACDigestPromiseErrorKey
,
testHMACDigestPromiseDatablobNull
,
testHMACDigestPromiseDatablobLong
};
export
{
testMDDigestPromise
,
testHMACDigestPromise
,
testHMACDigestPromiseDatablobLong
};
security/cryptoFramework/js_api_test_one/src/main/js/test/utils/symmetric/publicSymmetricPromise.js
浏览文件 @
c617ad84
...
@@ -560,7 +560,6 @@ async function encryptAndDecryptNormalProcessSuperdata(
...
@@ -560,7 +560,6 @@ async function encryptAndDecryptNormalProcessSuperdata(
for
(
i
=
0
;
i
<
globalTextLen
;
i
++
)
{
for
(
i
=
0
;
i
<
globalTextLen
;
i
++
)
{
globalText
+=
t
.
charAt
(
Math
.
floor
(
Math
.
random
()
*
n
));
globalText
+=
t
.
charAt
(
Math
.
floor
(
Math
.
random
()
*
n
));
}
}
console
.
warn
(
"
globalText1111111111111111111111111111111:
"
+
globalText
);
return
new
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
var
symKeyGenerator
=
createSymKeyGenerator
(
symAlgoName
);
var
symKeyGenerator
=
createSymKeyGenerator
(
symAlgoName
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录