未验证 提交 28e11006 编写于 作者: O openharmony_ci 提交者: Gitee

!6560 【OpenHarmony 3.2.8.5】【安全子系统】【master】加解密新增用例

Merge pull request !6560 from qiaozzzh/1117_1
......@@ -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 SHA384 for MD digest algotithm
* @tc.name Test SHA256 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 SHA384 for MD digest algotithm
* @tc.name Test SHA512 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 Test SHA384 for MD digest algotithm
* @tc.name The 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 Test SHA384 for MD digest algotithm
* @tc.name The 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 Test SHA384 for MD digest algotithm
* @tc.name The 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 Test SHA384 for MD digest algotithm
* @tc.name The 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 SHA1 for HMAC digest algorithm
* @tc.name Test SHA224 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 SHA1 for HMAC digest algorithm
* @tc.name Test SHA256 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 SHA1 for HMAC digest algorithm
* @tc.name Test SHA384 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 SHA1 for HMAC digest algorithm
* @tc.name Test SHA512 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 Test SHA1 for HMAC digest algorithm
* @tc.name The 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 Test SHA1 for HMAC digest algorithm
* @tc.name The 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 Test SHA1 for HMAC digest algorithm
* @tc.name The 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 Test SHA1 for HMAC digest algorithm
* @tc.name The 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) {
......
......@@ -52,19 +52,548 @@ export default function SymmetricCryptographyJsunit() {
}
);
/**
* @tc.number Security_crypto_framework_Symmetric_Encryption_AES_0200
* @tc.name Test AES192|GCM|PKCS7 normal encryption and decryption
* @tc.desc Use the Callback Style of Interface
*/
it(
"Security_crypto_framework_Symmetric_Encryption_AES_0200",
0,
async function (done) {
await symCallback
.encryptAndDecryptNormalProcess(
"AES192",
"AES192|GCM|PKCS7",
"genGcmParamsSpec"
)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_Symmetric_Encryption_AES_0200 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_Symmetric_Encryption_AES_0300
* @tc.name Test AES256|GCM|PKCS7 normal encryption and decryption
* @tc.desc Use the Callback Style of Interface
*/
it(
"Security_crypto_framework_Symmetric_Encryption_AES_0300",
0,
async function (done) {
await symCallback
.encryptAndDecryptNormalProcess(
"AES256",
"AES256|GCM|PKCS7",
"genGcmParamsSpec"
)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_Symmetric_Encryption_AES_0300 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_Symmetric_Encryption_AES_0400
* @tc.name Test AES256|ECB|PKCS7 normal encryption and decryption
* @tc.desc Use the Callback Style of Interface
*/
it(
"Security_crypto_framework_Symmetric_Encryption_AES_0400",
0,
async function (done) {
await symCallback
.encryptAndDecryptNormalProcess(
"AES256",
"AES256|ECB|PKCS7",
"null"
)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_Symmetric_Encryption_AES_0400 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_Symmetric_Encryption_AES_0500
* @tc.name Test AES256|CBC|PKCS7 normal encryption and decryption
* @tc.desc Use the Callback Style of Interface
*/
it(
"Security_crypto_framework_Symmetric_Encryption_AES_0500",
0,
async function (done) {
await symCallback
.encryptAndDecryptNormalProcess(
"AES256",
"AES256|CBC|PKCS7",
"genIvParamsSpec"
)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_Symmetric_Encryption_AES_0500 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_Symmetric_Encryption_AES_0600
* @tc.name Test AES256|CTR|PKCS7 normal encryption and decryption
* @tc.desc Use the Callback Style of Interface
*/
it(
"Security_crypto_framework_Symmetric_Encryption_AES_0600",
0,
async function (done) {
await symCallback
.encryptAndDecryptNormalProcess(
"AES256",
"AES256|CTR|PKCS7",
"genIvParamsSpec"
)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_Symmetric_Encryption_AES_0600 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_Symmetric_Encryption_AES_0700
* @tc.name Test AES256|0FB|PKCS7 normal encryption and decryption
* @tc.desc Use the Promise Style of Interface
*/
it(
"Security_crypto_framework_Symmetric_Encryption_AES_0700",
"Security_crypto_framework_Symmetric_Encryption_AES_0700",
0,
async function (done) {
await symPromise
.encryptAndDecryptNormalProcess(
"AES256",
"AES256|OFB|PKCS7",
"genIvParamsSpec"
)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_Symmetric_Encryption_AES_0700 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_Symmetric_Encryption_AES_0800
* @tc.name Test AES256|CFB|PKCS7 normal encryption and decryption
* @tc.desc Use the Promise Style of Interface
*/
it(
"Security_crypto_framework_Symmetric_Encryption_AES_0800",
0,
async function (done) {
await symPromise
.encryptAndDecryptNormalProcess(
"AES256",
"AES256|CFB|PKCS7",
"genIvParamsSpec"
)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_Symmetric_Encryption_AES_0800 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_Symmetric_Encryption_AES_0900
* @tc.name Test AES256|CCM|PKCS7 normal encryption and decryption
* @tc.desc Use the Promise Style of Interface
*/
it(
"Security_crypto_framework_Symmetric_Encryption_AES_0900",
0,
async function (done) {
await symPromise
.encryptAndDecryptNormalProcess(
"AES256",
"AES256|CCM|PKCS7",
"genCcmParamsSpec"
)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_Symmetric_Encryption_AES_0900 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_Symmetric_Encryption_AES_1000
* @tc.name Test AES256|GCM|PKCS5 normal encryption and decryption
* @tc.desc Use the Promise Style of Interface
*/
it(
"Security_crypto_framework_Symmetric_Encryption_AES_1000",
0,
async function (done) {
await symPromise
.encryptAndDecryptNormalProcess(
"AES256",
"AES256|GCM|PKCS5",
"genGcmParamsSpec"
)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_Symmetric_Encryption_AES_1000 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_Symmetric_Encryption_AES_1100
* @tc.name Test AES256|GCM|NoPadding normal encryption and decryption
* @tc.desc Use the Promise Style of Interface
*/
it(
"Security_crypto_framework_Symmetric_Encryption_AES_1100",
0,
async function (done) {
await symPromise
.encryptAndDecryptNormalProcess(
"AES256",
"AES256|GCM|NoPadding",
"genGcmParamsSpec"
)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_Symmetric_Encryption_AES_1100 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_Symmetric_Encryption_AES_1200
* @tc.name Test AES256|GCM|NoPadding normal encryption and decryption
* @tc.desc Use the Promise Style of Interface
*/
it(
"Security_crypto_framework_Symmetric_Encryption_AES_1200",
0,
async function (done) {
await symPromise
.encryptAndDecryptNormalProcess(
"AES128",
"AES128|GCM|NoPadding",
"genGcmParamsSpec"
)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_Symmetric_Encryption_AES_1200 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_Symmetric_Encryption_AES_1300
* @tc.name Test AES256 normal encryption and decryption
* @tc.desc Use the Promise Style of Interface
*/
it(
"Security_crypto_framework_Symmetric_Encryption_AES_1300",
0,
async function (done) {
await symPromise
.createSymKeyGeneratorFail(
"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();
});
await symPromise
.createSymKeyGeneratorFail(
"AESNULL",
)
.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();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_Symmetric_Encryption_AES_1400
* @tc.name Test AES128|NULL|PKCS7 normal encryption and decryption
* @tc.desc Use the Promise Style of Interface
*/
it(
"Security_crypto_framework_Symmetric_Encryption_AES_1400",
0,
async function (done) {
await symPromise
.createSymCipherFail(
"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();
});
await symPromise
.createSymCipherFail(
"AES128|ADF|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();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_Symmetric_Encryption_AES_1500
* @tc.name Test AES128|GCM|NULL normal encryption and decryption
* @tc.desc Use the Promise Style of Interface
*/
it(
"Security_crypto_framework_Symmetric_Encryption_AES_1500",
0,
async function (done) {
await symPromise
.createSymCipherFail(
"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();
});
await symPromise
.createSymCipherFail(
"AES128|GCM|CCCC",
)
.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();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_Symmetric_Encryption_3DES_0100
* @tc.name Test 3DES192|ECB|PKCS7 normal encryption and decryption
* @tc.desc Use the Promise Style of Interface
*/
it(
"Security_crypto_framework_Symmetric_Encryption_3DES_0100",
0,
async function (done) {
await symCallback
.encryptAndDecryptNormalProcess(
"3DES192",
"3DES192|ECB|PKCS7",
"genIvParamsSpec"
)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_Symmetric_Encryption_3DES_0100 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_Symmetric_Encryption_3DES_0200
* @tc.name Test 3DES192|CBC|PKCS7 normal encryption and decryption
* @tc.desc Use the Promise Style of Interface
*/
it(
"Security_crypto_framework_Symmetric_Encryption_3DES_0200",
0,
async function (done) {
await symCallback
.encryptAndDecryptNormalProcess(
"3DES192",
"3DES192|CBC|PKCS7",
"genIvParamsSpec"
)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_Symmetric_Encryption_3DES_0200 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_Symmetric_Encryption_3DES_0300
* @tc.name Test 3DES192|OFB|PKCS7 normal encryption and decryption
* @tc.desc Use the Promise Style of Interface
*/
it(
"Security_crypto_framework_Symmetric_Encryption_3DES_0300",
0,
async function (done) {
await symCallback
.encryptAndDecryptNormalProcess(
"3DES192",
"3DES192|OFB|PKCS7",
"genIvParamsSpec"
)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_Symmetric_Encryption_3DES_0300 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_Symmetric_Encryption_3DES_0400
* @tc.name Test 3DES192|CFB|PKCS7 normal encryption and decryption
* @tc.desc Use the Promise Style of Interface
*/
it(
"Security_crypto_framework_Symmetric_Encryption_3DES_0400",
0,
async function (done) {
await symPromise
.encryptAndDecryptNormalProcess(
"AES256",
"AES256|OFB|PKCS7",
"3DES192",
"3DES192|CFB|PKCS7",
"genIvParamsSpec"
)
.then((data) => {
......@@ -72,8 +601,243 @@ export default function SymmetricCryptographyJsunit() {
})
.catch((err) => {
console.error(
"Security_crypto_framework_Symmetric_Encryption_AES_0700 catch error: " +
err
"Security_crypto_framework_Symmetric_Encryption_3DES_0400 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_Symmetric_Encryption_3DES_0500
* @tc.name Test 3DES192|ECB|PKCS5 normal encryption and decryption
* @tc.desc Use the Promise Style of Interface
*/
it(
"Security_crypto_framework_Symmetric_Encryption_3DES_0500",
0,
async function (done) {
await symPromise
.encryptAndDecryptNormalProcess(
"3DES192",
"3DES192|ECB|PKCS5",
"genIvParamsSpec"
)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_Symmetric_Encryption_3DES_0500 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_Symmetric_Encryption_3DES_0600
* @tc.name Test 3DES192|ECB|NoPadding normal encryption and decryption
* @tc.desc Use the Promise Style of Interface
*/
it(
"Security_crypto_framework_Symmetric_Encryption_3DES_0600",
0,
async function (done) {
await symPromise
.encryptAndDecryptNormalProcess(
"3DES192",
"3DES192|ECB|NoPadding",
"null"
)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_Symmetric_Encryption_3DES_0600 catch error: " +
err
);
expect(err == "Error: doFinal failed.").assertTrue();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_Symmetric_Encryption_3DES_0700
* @tc.name Test 3DES192|null|PKCS7 and 3DES192|DDD|PKCS7 normal encryption and decryption
* @tc.desc Use the Promise Style of Interface
*/
it(
"Security_crypto_framework_Symmetric_Encryption_3DES_0700",
0,
async function (done) {
await symPromise
.encryptAndDecryptNormalProcess(
"3DES192",
"3DES192|null|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();
});
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();
}
);
/**
* @tc.number Security_crypto_framework_Symmetric_Encryption_3DES_0800
* @tc.name Test 3DES192|ECB|null and 3DES192|ECB|CCCCC normal encryption and decryption
* @tc.desc Use the Promise Style of Interface
*/
it(
"Security_crypto_framework_Symmetric_Encryption_3DES_0800",
0,
async function (done) {
await symPromise
.encryptAndDecryptNormalProcess(
"3DES192",
"3DES192|ECB|null",
"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();
});
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();
}
);
/**
* @tc.number Security_crypto_framework_Symmetric_Encryption_AES_2000
* @tc.name Test AES256|CCM|PKCS7 normal encryption and decryption
* @tc.desc Use the Promise Style of Interface
*/
it(
"Security_crypto_framework_Symmetric_Encryption_AES_2000",
0,
async function (done) {
await symPromise
.encryptAndDecryptNormalProcessSuperdata(
"AES256",
"AES256|CCM|PKCS7",
"genCcmParamsSpec"
)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_Symmetric_Encryption_AES_2000 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_Symmetric_Encryption_AES_3000
* @tc.name Test AES256|CCM|PKCS7 normal encryption and decryption
* @tc.desc Use the Promise Style of Interface
*/
it(
"Security_crypto_framework_Symmetric_Encryption_AES_3000",
0,
async function (done) {
await symPromise
.encryptAndDecryptNormalProcessSpecialdata(
"AES256",
"AES256|CCM|PKCS7",
"genCcmParamsSpec"
)
.then((data) => {
expect(data == "TypeError: Cannot read property length of null").assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_Symmetric_Encryption_AES_3000 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_Symmetric_Encryption_3DES_2000
* @tc.name Test 3DES192|ECB|PKCS7 normal encryption and decryption
* @tc.desc Use the Promise Style of Interface
*/
it(
"Security_crypto_framework_Symmetric_Encryption_3DES_2000",
0,
async function (done) {
await symPromise
.encryptAndDecryptNormalProcessSuperdata(
"3DES192",
"3DES192|ECB|PKCS7",
"null"
)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_Symmetric_Encryption_3DES_2000 catch error: " +
err
);
expect(null).assertFail();
});
......@@ -110,6 +874,35 @@ export default function SymmetricCryptographyJsunit() {
}
);
/**
* @tc.number Security_crypto_framework_Symmetric_Encryption_AES_2200
* @tc.name Test AES192|GCM|PKCS7 convertKey encryption and decryption
* @tc.desc Use the Callback Style of Interface
*/
it(
"Security_crypto_framework_Symmetric_Encryption_AES_2200",
0,
async function (done) {
await symCallback
.convertKeyEncryptAndDecryptProcess(
"AES192",
"AES192|GCM|PKCS7",
"genGcmParamsSpec"
)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_Symmetric_Encryption_AES_2200 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_Symmetric_Encryption_AES_2300
* @tc.name Test AES256|GCM|PKCS7 convertKey encryption and decryption
......@@ -139,6 +932,64 @@ export default function SymmetricCryptographyJsunit() {
}
);
/**
* @tc.number Security_crypto_framework_Symmetric_Encryption_3DES_2100
* @tc.name Test 3DES192|ECB|PKCS7 convertKey encryption and decryption
* @tc.desc Use the Promise Style of Interface
*/
it(
"Security_crypto_framework_Symmetric_Encryption_3DES_2100",
0,
async function (done) {
await symCallback
.convertKeyEncryptAndDecryptProcess(
"3DES192",
"3DES192|ECB|PKCS7",
"null"
)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_Symmetric_Encryption_3DES_2100 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_Symmetric_Encryption_3DES_2200
* @tc.name Test 3DES192|ECB|PKCS7 convertKey encryption and decryption
* @tc.desc Use the Promise Style of Interface
*/
it(
"Security_crypto_framework_Symmetric_Encryption_3DES_2200",
0,
async function (done) {
await symPromise
.convertKeyEncryptAndDecryptProcess(
"3DES192",
"3DES192|ECB|PKCS7",
"null"
)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_Symmetric_Encryption_3DES_2200 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_Symmetric_Encryption_AES_3700
* @tc.name Test clearMem interface
......
......@@ -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();
})
......
......@@ -154,11 +154,153 @@ async function doFinalCipher(cipherGenerator, mode, dataBlob) {
});
}
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 = null;
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) => {
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();
}
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";
......@@ -169,6 +311,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 +378,11 @@ async function encryptAndDecryptNormalProcess(
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) => {
......@@ -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,
};
......@@ -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.
先完成此消息的编辑!
想要评论请 注册