提交 b99c8880 编写于 作者: Q qiaozzzh

XTS Failure Case Maintenance

Signed-off-by: Nqiaozzzh <qiaozhang@huawei.com>
Change-Id: Id784febd928e2812aa499eb66bb3e2367a7d2a66
上级 dffe1b26
......@@ -18,655 +18,657 @@ import * as asyPromise from "./utils/asymmetric/publicAsymmetricPromise";
import * as asyCallback from "./utils/asymmetric/publicAsymmetricCallback";
export default function AsymmetricCryptographyJsunit() {
describe("AsymmetricCryptographyJsunit", function () {
console.info("##########start AsymmetricCryptographyJsunit##########");
beforeAll(function () {});
afterEach(function () {});
describe("AsymmetricCryptographyJsunit", function () {
console.info("##########start AsymmetricCryptographyJsunit##########");
beforeAll(function () {
});
afterEach(function () {
});
/**
* @tc.number Security_crypto_framework_ASymmetric_Encryption_RSA_0100
* @tc.name Test RSA1024|PRIMES_2 normal encryption and decryption
* @tc.desc Use the Callback Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_Encryption_RSA_0100",
0,
async function (done) {
await asyCallback
.encryptAndDecryptNormalProcess(
"RSA1024|PRIMES_2",
"RSA1024|PKCS1|SHA256"
)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_Encryption_RSA_0100 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_Encryption_RSA_0100
* @tc.name Test RSA1024|PRIMES_2 normal encryption and decryption
* @tc.desc Use the Callback Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_Encryption_RSA_0100",
0,
async function (done) {
await asyCallback
.encryptAndDecryptNormalProcess(
"RSA1024|PRIMES_2",
"RSA1024|PKCS1|SHA256"
)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_Encryption_RSA_0100 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_Encryption_RSA_0200
* @tc.name Test RSA2048|PRIMES_2 normal encryption and decryption
* @tc.desc Use the Promise Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_Encryption_RSA_0200",
0,
async function (done) {
await asyPromise
.encryptAndDecryptNormalProcess(
"RSA2048|PRIMES_2",
"RSA2048|PKCS1|MD5"
)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_Encryption_RSA_0200 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_Encryption_RSA_0200
* @tc.name Test RSA2048|PRIMES_2 normal encryption and decryption
* @tc.desc Use the Promise Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_Encryption_RSA_0200",
0,
async function (done) {
await asyPromise
.encryptAndDecryptNormalProcess(
"RSA2048|PRIMES_2",
"RSA2048|PKCS1|MD5"
)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_Encryption_RSA_0200 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_Encryption_RSA_0300
* @tc.name Test RSA3072 normal encryption and decryption
* @tc.desc Use the Callback Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_Encryption_RSA_0300",
0,
async function (done) {
await asyCallback
.encryptAndDecryptNormalProcess(
"RSA3072",
"RSA3072|PKCS1|SHA224"
)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_Encryption_RSA_0300 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_Encryption_RSA_0300
* @tc.name Test RSA3072 normal encryption and decryption
* @tc.desc Use the Callback Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_Encryption_RSA_0300",
0,
async function (done) {
await asyCallback
.encryptAndDecryptNormalProcess(
"RSA3072",
"RSA3072|PKCS1|SHA224"
)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_Encryption_RSA_0300 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_Encryption_RSA_0400
* @tc.name Test RSA4096 normal encryption and decryption
* @tc.desc Use the Promise Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_Encryption_RSA_0400",
0,
async function (done) {
await asyPromise
.encryptAndDecryptNormalProcess(
"RSA4096",
"RSA4096|PKCS1_OAEP|MD5|MGF1_SHA512"
)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_Encryption_RSA_0400 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_Encryption_RSA_0400
* @tc.name Test RSA4096 normal encryption and decryption
* @tc.desc Use the Promise Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_Encryption_RSA_0400",
0,
async function (done) {
await asyPromise
.encryptAndDecryptNormalProcess(
"RSA4096",
"RSA4096|PKCS1_OAEP|MD5|MGF1_SHA512"
)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_Encryption_RSA_0400 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_Encryption_RSA_0500
* @tc.name Test RSA3072 normal encryption and decryption
* @tc.desc Use the Callback Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_Encryption_RSA_0500",
0,
async function (done) {
await asyCallback
.encryptAndDecryptNormalProcess(
"RSA8192",
"RSA8192|PKCS1_OAEP|SHA1|MGF1_SHA384"
)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_Encryption_RSA_0500 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_Encryption_RSA_0500
* @tc.name Test RSA3072 normal encryption and decryption
* @tc.desc Use the Callback Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_Encryption_RSA_0500",
0,
async function (done) {
await asyCallback
.encryptAndDecryptNormalProcess(
"RSA8192",
"RSA8192|PKCS1_OAEP|SHA1|MGF1_SHA384"
)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_Encryption_RSA_0500 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_Encryption_RSA_0600
* @tc.name Test RSA3072|PKCS1|SHA256 normal encryption and decryption
* @tc.desc Use the Promise Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_Encryption_RSA_0600",
0,
async function (done) {
await asyPromise
.encryptAndDecryptNormalProcess(
"RSA3072|PRIMES_3",
"RSA3072|PKCS1|SHA256"
)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_Encryption_RSA_0600 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_Encryption_RSA_0600
* @tc.name Test RSA3072|PKCS1|SHA256 normal encryption and decryption
* @tc.desc Use the Promise Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_Encryption_RSA_0600",
0,
async function (done) {
await asyPromise
.encryptAndDecryptNormalProcess(
"RSA3072|PRIMES_3",
"RSA3072|PKCS1|SHA256"
)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_Encryption_RSA_0600 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_Encryption_RSA_0700
* @tc.name Test RSA3072|PKCS1|SHA512 normal encryption and decryption
* @tc.desc Use the Callback Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_Encryption_RSA_0700",
0,
async function (done) {
await asyCallback
.encryptAndDecryptNormalProcess(
"RSA3072",
"RSA3072|PKCS1|SHA512"
)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_Encryption_RSA_0700 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_Encryption_RSA_0700
* @tc.name Test RSA3072|PKCS1|SHA512 normal encryption and decryption
* @tc.desc Use the Callback Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_Encryption_RSA_0700",
0,
async function (done) {
await asyCallback
.encryptAndDecryptNormalProcess(
"RSA3072",
"RSA3072|PKCS1|SHA512"
)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_Encryption_RSA_0700 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_Encryption_RSA_0800
* @tc.name Test RSA3072|PKCS1_OAEP|SHA224|MGF1_SHA256 normal encryption and decryption
* @tc.desc Use the Promise Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_Encryption_RSA_0800",
0,
async function (done) {
await asyPromise
.encryptAndDecryptNormalProcess(
"RSA3072",
"RSA3072|PKCS1_OAEP|SHA224|MGF1_SHA256"
)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_Encryption_RSA_0800 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_Encryption_RSA_0800
* @tc.name Test RSA3072|PKCS1_OAEP|SHA224|MGF1_SHA256 normal encryption and decryption
* @tc.desc Use the Promise Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_Encryption_RSA_0800",
0,
async function (done) {
await asyPromise
.encryptAndDecryptNormalProcess(
"RSA3072",
"RSA3072|PKCS1_OAEP|SHA224|MGF1_SHA256"
)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_Encryption_RSA_0800 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_Encryption_RSA_0900
* @tc.name Test RSA512|PKCS1_OAEP|SHA256|MGF1_SHA224 normal encryption and decryption
* @tc.desc Use the Callback Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_Encryption_RSA_0900",
0,
async function (done) {
await asyCallback
.encryptAndDecryptNormalProcess(
"RSA1024",
"RSA1024|PKCS1_OAEP|SHA256|MGF1_SHA224"
)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_Encryption_RSA_0900 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_Encryption_RSA_0900
* @tc.name Test RSA512|PKCS1_OAEP|SHA256|MGF1_SHA224 normal encryption and decryption
* @tc.desc Use the Callback Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_Encryption_RSA_0900",
0,
async function (done) {
await asyCallback
.encryptAndDecryptNormalProcess(
"RSA1024",
"RSA1024|PKCS1_OAEP|SHA256|MGF1_SHA224"
)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_Encryption_RSA_0900 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_Encryption_RSA_1000
* @tc.name Test RSA3072|PKCS1_OAEP|SHA384|MGF1_SHA1 normal encryption and decryption
* @tc.desc Use the Promise Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_Encryption_RSA_1000",
0,
async function (done) {
await asyPromise
.encryptAndDecryptNormalProcess(
"RSA3072|PRIMES_3",
"RSA3072|PKCS1_OAEP|SHA384|MGF1_SHA1"
)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_Encryption_RSA_1000 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_Encryption_RSA_1000
* @tc.name Test RSA3072|PKCS1_OAEP|SHA384|MGF1_SHA1 normal encryption and decryption
* @tc.desc Use the Promise Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_Encryption_RSA_1000",
0,
async function (done) {
await asyPromise
.encryptAndDecryptNormalProcess(
"RSA3072|PRIMES_3",
"RSA3072|PKCS1_OAEP|SHA384|MGF1_SHA1"
)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_Encryption_RSA_1000 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_Encryption_RSA_1100
* @tc.name Test RSA3072|PKCS1_OAEP|SHA512|MGF1_MD5 normal encryption and decryption
* @tc.desc Use the Callback Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_Encryption_RSA_1100",
0,
async function (done) {
await asyCallback
.encryptAndDecryptNormalProcess(
"RSA3072",
"RSA3072|PKCS1_OAEP|SHA512|MGF1_MD5"
)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_Encryption_RSA_1100 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_Encryption_RSA_1100
* @tc.name Test RSA3072|PKCS1_OAEP|SHA512|MGF1_MD5 normal encryption and decryption
* @tc.desc Use the Callback Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_Encryption_RSA_1100",
0,
async function (done) {
await asyCallback
.encryptAndDecryptNormalProcess(
"RSA3072",
"RSA3072|PKCS1_OAEP|SHA512|MGF1_MD5"
)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_Encryption_RSA_1100 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_Encryption_RSA_1200
* @tc.name Test RSA3072|PKCS1 normal encryption and decryption
* @tc.desc Use the Promise Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_Encryption_RSA_1200",
0,
async function (done) {
await asyPromise
.encryptAndDecryptNormalProcess(
"RSA3072",
"RSA3072|PKCS1"
)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_Encryption_RSA_1200 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_Encryption_RSA_1200
* @tc.name Test RSA3072|PKCS1 normal encryption and decryption
* @tc.desc Use the Promise Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_Encryption_RSA_1200",
0,
async function (done) {
await asyPromise
.encryptAndDecryptNormalProcess(
"RSA3072",
"RSA3072|PKCS1"
)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_Encryption_RSA_1200 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_Encryption_RSA_1300
* @tc.name Test RSA4096|PKCS1 normal encryption and decryption
* @tc.desc Use the Callback Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_Encryption_RSA_1300",
0,
async function (done) {
await asyCallback
.encryptAndDecryptNormalProcess(
"RSA4096",
"RSA4096|PKCS1"
)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_Encryption_RSA_1300 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_Encryption_RSA_1300
* @tc.name Test RSA4096|PKCS1 normal encryption and decryption
* @tc.desc Use the Callback Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_Encryption_RSA_1300",
0,
async function (done) {
await asyCallback
.encryptAndDecryptNormalProcess(
"RSA4096",
"RSA4096|PKCS1"
)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_Encryption_RSA_1300 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_Encryption_RSA_1400
* @tc.name Test RSA4096|PKCS1 normal encryption and decryption
* @tc.desc Use the Callback Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_Encryption_RSA_1400",
0,
async function (done) {
await asyCallback
.encryptAndDecryptNormalProcessNull(
"RSA4096",
"RSA4096|PKCS1"
)
.then((data) => {
expect(data == "Error: doFinal failed.").assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_Encryption_RSA_1400 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_Encryption_RSA_1400
* @tc.name Test RSA4096|PKCS1 normal encryption and decryption
* @tc.desc Use the Callback Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_Encryption_RSA_1400",
0,
async function (done) {
await asyCallback
.encryptAndDecryptNormalProcessNull(
"RSA4096",
"RSA4096|PKCS1"
)
.then((data) => {
expect(data == "Error: doFinal failed.").assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_Encryption_RSA_1400 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_0100
* @tc.name Test RSA1024|PKCS1|MD5 normal sign and verify
* @tc.desc Use the Callback Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_0100",
0,
async function (done) {
await asyCallback
.signAndVerifyNormalProcess("RSA1024|PRIMES_2", "RSA1024|PKCS1|MD5")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_0100 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_0100
* @tc.name Test RSA1024|PKCS1|MD5 normal sign and verify
* @tc.desc Use the Callback Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_0100",
0,
async function (done) {
await asyCallback
.signAndVerifyNormalProcess("RSA1024|PRIMES_2", "RSA1024|PKCS1|MD5")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_0100 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_0200
* @tc.name Test RSA2048|PKCS1|SHA1 normal sign and verify
* @tc.desc Use the Promise Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_0200",
0,
async function (done) {
await asyPromise
.signAndVerifyNormalProcess("RSA2048|PRIMES_2", "RSA2048|PKCS1|SHA1")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_0200 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_0200
* @tc.name Test RSA2048|PKCS1|SHA1 normal sign and verify
* @tc.desc Use the Promise Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_0200",
0,
async function (done) {
await asyPromise
.signAndVerifyNormalProcess("RSA2048|PRIMES_2", "RSA2048|PKCS1|SHA1")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_0200 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_0300
* @tc.name Test RSA3072|PKCS1|SHA224 normal sign and verify
* @tc.desc Use the Callback Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_0300",
0,
async function (done) {
await asyCallback
.signAndVerifyNormalProcess("RSA3072|PRIMES_2", "RSA3072|PKCS1|SHA224")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_0300 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_0300
* @tc.name Test RSA3072|PKCS1|SHA224 normal sign and verify
* @tc.desc Use the Callback Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_0300",
0,
async function (done) {
await asyCallback
.signAndVerifyNormalProcess("RSA3072|PRIMES_2", "RSA3072|PKCS1|SHA224")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_0300 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_0400
* @tc.name Test RSA2048|PKCS1|SHA1 normal sign and verify
* @tc.desc Use the Promise Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_0400",
0,
async function (done) {
await asyPromise
.signAndVerifyNormalProcess("RSA4096|PRIMES_2", "RSA4096|PKCS1|SHA256")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_0400 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_0400
* @tc.name Test RSA2048|PKCS1|SHA1 normal sign and verify
* @tc.desc Use the Promise Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_0400",
0,
async function (done) {
await asyPromise
.signAndVerifyNormalProcess("RSA4096|PRIMES_2", "RSA4096|PKCS1|SHA256")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_0400 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_0500
* @tc.name Test RSA8192|PKCS1|SHA384 normal sign and verify
* @tc.desc Use the Promise Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_0500",
0,
async function (done) {
await asyPromise
.signAndVerifyNormalProcess("RSA8192|PRIMES_3", "RSA8192|PKCS1|SHA384")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_0500 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_0500
* @tc.name Test RSA8192|PKCS1|SHA384 normal sign and verify
* @tc.desc Use the Promise Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_0500",
0,
async function (done) {
await asyPromise
.signAndVerifyNormalProcess("RSA8192|PRIMES_3", "RSA8192|PKCS1|SHA384")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_0500 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_0600
* @tc.name Test RSA512|PKCS1|SHA512 normal sign and verify
* @tc.desc Use the Promise Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_0600",
0,
async function (done) {
await asyPromise
.signAndVerifyNormalProcess("RSA512|PRIMES_2", "RSA512|PKCS1|SHA256")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_0600 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_0600
* @tc.name Test RSA512|PKCS1|SHA512 normal sign and verify
* @tc.desc Use the Promise Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_0600",
0,
async function (done) {
await asyPromise
.signAndVerifyNormalProcess("RSA512|PRIMES_2", "RSA512|PKCS1|SHA256")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_0600 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_0700
* @tc.name Test RSA1024|PKCS1|MD5|MGF1_MD5 normal sign and verify
* @tc.desc Use the Callback Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_0700",
0,
async function (done) {
await asyCallback
.signAndVerifyNormalProcess("RSA1024", "RSA1024|PKCS1|MD5|MGF1_MD5")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_0700 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_0700
* @tc.name Test RSA1024|PKCS1|MD5|MGF1_MD5 normal sign and verify
* @tc.desc Use the Callback Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_0700",
0,
async function (done) {
await asyCallback
.signAndVerifyNormalProcess("RSA1024", "RSA1024|PKCS1|MD5|MGF1_MD5")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_0700 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_0800
* @tc.name Test RSA2048|PSS|SHA1|MGF1_SHA1 normal sign and verify
* @tc.desc Use the Promise Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_0800",
0,
async function (done) {
await asyPromise
.signAndVerifyNormalProcess("RSA2048", "RSA2048|PSS|SHA1|MGF1_SHA1")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_0800 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_0800
* @tc.name Test RSA2048|PSS|SHA1|MGF1_SHA1 normal sign and verify
* @tc.desc Use the Promise Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_0800",
0,
async function (done) {
await asyPromise
.signAndVerifyNormalProcess("RSA2048", "RSA2048|PSS|SHA1|MGF1_SHA1")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_0800 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_0900
* @tc.name Test RSA3072|PSS|SHA224|MGF1_SHA224 normal sign and verify
* @tc.desc Use the Callback Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_0900",
0,
async function (done) {
await asyCallback
.signAndVerifyNormalProcess("RSA3072", "RSA3072|PSS|SHA224|MGF1_SHA224")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_0900 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_0900
* @tc.name Test RSA3072|PSS|SHA224|MGF1_SHA224 normal sign and verify
* @tc.desc Use the Callback Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_0900",
0,
async function (done) {
await asyCallback
.signAndVerifyNormalProcess("RSA3072", "RSA3072|PSS|SHA224|MGF1_SHA224")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_0900 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_1000
* @tc.name Test RSA4096|PSS|SHA256|MGF1_SHA256 normal sign and verify
* @tc.desc Use the Callback Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_1000",
0,
async function (done) {
await asyCallback
.signAndVerifyNormalProcess("RSA4096", "RSA4096|PSS|SHA256|MGF1_SHA256")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_1000 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_1000
* @tc.name Test RSA4096|PSS|SHA256|MGF1_SHA256 normal sign and verify
* @tc.desc Use the Callback Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_1000",
0,
async function (done) {
await asyCallback
.signAndVerifyNormalProcess("RSA4096", "RSA4096|PSS|SHA256|MGF1_SHA256")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_1000 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
});
});
}
\ No newline at end of file
......@@ -16,733 +16,758 @@
import { describe, beforeAll, afterEach, it, expect } from "@ohos/hypium";
import * as asyPromise from "./utils/asymmetric/publicAsymmetricPromise";
import * as asyCallback from "./utils/asymmetric/publicAsymmetricCallback";
import cryptoFramework from "@ohos.security.cryptoFramework";
export default function AsymmetricCryptographyJsSecondunit() {
describe("AsymmetricCryptographyJsSecondunit", function () {
console.info("##########start AsymmetricCryptographyJsunit##########");
beforeAll(function () {});
afterEach(function () {});
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_1200
* @tc.name Test RSA2048|PSS|SHA1|MGF1_SHA1 normal sign and verify
* @tc.desc Use the Promise Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_1200",
0,
async function (done) {
await asyPromise
.signAndVerifyNormalProcess("RSA512", "RSA512|PSS|SHA384|MGF1_SHA384")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_1200 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_5000
* @tc.name Test RSA2048|PSS|SHA1|MGF1_SHA1 normal sign and verify
* @tc.desc Use the Promise Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_5000",
0,
async function (done) {
await asyPromise
.signAndVerifyNormalProcessDataException("RSA512", "RSA512|PSS|SHA384|MGF1_SHA384", "null")
.then((data) => {
expect(data == "Error: [Data]: must be of the DataBlob type.").assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_5000 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_1300
* @tc.name Test RSA256 or null normal sign and verify
* @tc.desc Use the Promise Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_1300",
0,
async function (done) {
await asyPromise
.createAsyKeyGeneratorFail("RSA256")
.then((data) => {
expect(data == "TypeError: Cannot read property algName of null").assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_1300 catch error: " +
err
);
expect(null).assertFail();
});
await asyPromise
.createAsyKeyGeneratorFail("null")
.then((data) => {
expect(data == "TypeError: Cannot read property algName of null").assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_1300 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_1400
* @tc.name Test RSA2048|PSS|SHA1|MGF1_SHA1 normal sign and verify
* @tc.desc Use the Promise Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_1400",
0,
async function (done) {
await asyPromise
.createAsySignFail(
"RSA3072",
"RSA4096|null|SHA256",
"RSA4096|PKCS1|null",
"RSA4096|PKCS1|SHA122",
"RSA4096|PKCS3|SHA256"
)
.then((data) => {
expect(data == "TypeError: Cannot read property algName of undefined").assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_1400 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_Encryption_RSA_2000
* @tc.name Test RSA4096|PKCS1 normal encryption and decryption
* @tc.desc Use the Callback Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_Encryption_RSA_2000",
0,
async function (done) {
await asyCallback
.encryptAndDecryptNormalProcessSuperdata(
"RSA4096",
"RSA4096|PKCS1",
"490"
)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_Encryption_RSA_2000 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_2100
* @tc.name Test RSA3072|PKCS1|SHA224 normal sign and verify
* @tc.desc Use the Callback Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_2100",
0,
async function (done) {
await asyCallback
.signAndVerifyNormalProcessSuperdata(
"RSA3072",
"RSA3072|PKCS1|SHA224",
"350"
)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_2100 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_1500
* @tc.name Test RSA2048|PSS|SHA1|MGF1_SHA1 normal sign and verify
* @tc.desc Use the Promise Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_1500",
0,
async function (done) {
await asyPromise
.createAsyVerifyFail(
"RSA3072",
"RSA4096|null|SHA256",
"RSA4096|PKCS1|null",
"RSA4096|PKCS1|SHA122",
"RSA4096|PKCS3|SHA256"
)
.then((data) => {
expect(data == "TypeError: Cannot read property algName of undefined").assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_1500 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0100
* @tc.name Test ECC224|SHA256 normal sign and verify
* @tc.desc Use the Callback Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0100",
0,
async function (done) {
await asyCallback
.signAndVerifyNormalProcess("ECC224", "ECC224|SHA256")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0100 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0200
* @tc.name Test ECC256|SHA1 normal sign and verify
* @tc.desc Use the Promise Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0200",
0,
async function (done) {
await asyPromise
.signAndVerifyNormalProcess("ECC256", "ECC256|SHA1")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0200 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0300
* @tc.name Test ECC224|SHA256 normal sign and verify
* @tc.desc Use the Callback Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0300",
0,
async function (done) {
await asyCallback
.signAndVerifyNormalProcess("ECC384", "ECC384|SHA224")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0300 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0400
* @tc.name Test ECC521|SHA384 normal sign and verify
* @tc.desc Use the Callback Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0400",
0,
async function (done) {
await asyPromise
.signAndVerifyNormalProcess("ECC521", "ECC521|SHA384")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0400 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0500
* @tc.name Test ECC224|SHA512 normal sign and verify
* @tc.desc Use the Callback Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0500",
0,
async function (done) {
await asyPromise
.signAndVerifyNormalProcess("ECC224", "ECC224|SHA512")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0500 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0600
* @tc.name Test ECC1 or NULL normal sign and verify
* @tc.desc Use the Callback Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0600",
0,
async function (done) {
await asyCallback
.createAsyKeyGeneratorFail("ECC1")
.then((data) => {
expect(data == "TypeError: Cannot read property algName of null").assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0600 catch error: " +
err
);
expect(null).assertFail();
});
await asyCallback
.createAsyKeyGeneratorFail("null")
.then((data) => {
expect(data == "TypeError: Cannot read property algName of null").assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0600 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0700
* @tc.name Test ECC224 normal sign and verify
* @tc.desc Use the Callback Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0700",
0,
async function (done) {
await asyPromise
.createAsySignFail(
"ECC224",
"ECC224|SHA257",
"ECC224|NULL",
"NULL|SHA1",
"ECC|SHA"
)
.then((data) => {
expect(data == "TypeError: Cannot read property algName of undefined").assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0700: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0800
* @tc.name Test RSA3072 normal sign and verify
* @tc.desc Use the Callback Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0800",
0,
async function (done) {
await asyPromise
.createAsyVerifyFail(
"ECC224",
"ECC1|SHA256",
"NULL|SHA256",
"ECC224|SHA122",
"ECC224|NULL"
)
.then((data) => {
expect(data == "TypeError: Cannot read property algName of undefined").assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0800 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0900
* @tc.name Test ECC224|SHA512 normal sign and verify
* @tc.desc Use the Callback Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0900",
0,
async function (done) {
await asyCallback
.signAndVerifyNormalProcessSuperdata(
"ECC224",
"ECC224|SHA512",
"350"
)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0900 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_ECDH_0100
* @tc.name Test ECC224 SignVerify ECDH
* @tc.desc Use the Promise Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_ECDH_0100",
0,
async function (done) {
await asyPromise
.keyAgreementProcess("ECC224")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_ECDH_0100 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_ECDH_0200
* @tc.name Test ECC256 SignVerify ECDH
* @tc.desc Use the Callback Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_ECDH_0200",
0,
async function (done) {
await asyCallback
.keyAgreementProcess("ECC256")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_ECDH_0200 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_ECDH_0300
* @tc.name Test ECC384 SignVerify ECDH
* @tc.desc Use the Promise Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_ECDH_0300",
0,
async function (done) {
await asyPromise
.keyAgreementProcess("ECC384")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_ECDH_0300 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_ECDH_0400
* @tc.name Test ECC521 SignVerify ECDH
* @tc.desc Use the Callback Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_ECDH_0400",
0,
async function (done) {
await asyCallback
.keyAgreementProcess("ECC521")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_ECDH_0400 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_ECDH_0500
* @tc.name Test ECC5 or null SignVerify ECDH
* @tc.desc Use the Callback Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_ECDH_0500",
0,
async function (done) {
await asyCallback
.createAsyKeyAgreementFail("ECC5")
.then((data) => {
expect(data == "TypeError: Cannot read property algName of undefined").assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_ECDH_0500 catch error: " +
err
);
expect(null).assertFail();
});
await asyCallback
.createAsyKeyAgreementFail("null")
.then((data) => {
expect(data == "TypeError: Cannot read property algName of undefined").assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_ECDH_0500 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_ECDH_0600
* @tc.name Test ECC256 SignVerify ECDH
* @tc.desc Use the Callback Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_ECDH_0600",
0,
async function (done) {
await asyCallback
.keyAgreementProcessParameterException("ECC256")
.then((data) => {
expect(data == "Error: [PriKey]: param unwarp error.").assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_ECDH_0600 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_ECDH_0700
* @tc.name Test RSA3072 SignVerify ECDH
* @tc.desc Use the Callback Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_ECDH_0700",
0,
async function (done) {
await asyCallback
.keyAgreementProcessFail("RSA3072", "ECC521")
.then((data) => {
expect(data == "Error: An exception occurs.").assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_ECDH_0700 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_Encryption_RSA_3300
* @tc.name Test convertKey
* @tc.desc Use RSA3072|PRIMES_2 algorithm
*/
it(
"Security_crypto_framework_ASymmetric_Encryption_RSA_3300",
0,
async function (done) {
await asyPromise
.convertKeyEncryptAndDecryptProcess("RSA3072|PRIMES_2")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_Encryption_RSA_3300 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_Encryption_RSA_3100
* @tc.name Test convertKey
* @tc.desc Use RSA1024|PRIMES_2 algorithm
*/
it(
"Security_crypto_framework_ASymmetric_Encryption_RSA_3100",
0,
async function (done) {
await asyPromise
.AsyPriKeyClearProcess("RSA1024|PRIMES_2")
.then((data) => {
expect(data == null).assertTrue();
console.info("##########start AsymmetricCryptographyJsunit##########");
beforeAll(function () {
});
afterEach(function () {
});
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_1200
* @tc.name Test RSA2048|PSS|SHA1|MGF1_SHA1 normal sign and verify
* @tc.desc Use the Promise Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_1200",
0,
async function (done) {
await asyPromise
.signAndVerifyNormalProcess("RSA512", "RSA512|PSS|SHA384|MGF1_SHA384")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_1200 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_5000
* @tc.name Test RSA512|PSS|SHA384|MGF1_SHA384 sign and verify with NULL input
* @tc.desc Use the Promise Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_5000",
0,
async function (done) {
await asyPromise
.signAndVerifyNormalProcessDataException("RSA512", "RSA512|PSS|SHA384|MGF1_SHA384", "null")
.then((data) => {
expect(data).assertEqual(401);
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_5000 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_1300
* @tc.name Test createAsyKeyGenerator interface with invalid input
* @tc.desc First input RSA256, Second input NULL
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_1300",
0,
async function (done) {
try {
cryptoFramework.createAsyKeyGenerator("RSA256");
} catch (err) {
console.error("err is:" + err.code);
expect(err.code).assertEqual(401);
}
try {
cryptoFramework.createAsyKeyGenerator("NULL");
} catch (err) {
console.error("err is:" + err.code);
expect(err.code).assertEqual(401);
}
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_1400
* @tc.name Test createSign interface with invalid input
* @tc.desc First input RSA4096|NULL|SHA256, Second input RSA4096|PKCS1|NULL
* @tc.desc Third input RSA4096|PKCS1|SHA122, Fourth input RSA4096|PKCS5|SHA256
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_1400",
0,
async function (done) {
try {
let rsaGenerator = cryptoFramework.createAsyKeyGenerator("RSA3072");
await rsaGenerator.generateKeyPair();
cryptoFramework.createSign("RSA4096|NULL|SHA256");
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
cryptoFramework.createSign("RSA4096|PKCS1|NULL");
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
cryptoFramework.createSign("RSA4096|PKCS1|SHA122");
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
cryptoFramework.createSign("RSA4096|PKCS5|SHA256");
} catch (err) {
expect(err.code).assertEqual(401);
}
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_Encryption_RSA_2000
* @tc.name Test RSA4096|PKCS1 normal encryption and decryption
* @tc.desc Use the Callback Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_Encryption_RSA_2000",
0,
async function (done) {
await asyCallback
.encryptAndDecryptNormalProcessSuperdata(
"RSA4096",
"RSA4096|PKCS1",
"490"
)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_Encryption_RSA_2000 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_2100
* @tc.name Test RSA3072|PKCS1|SHA224 normal sign and verify
* @tc.desc Use the Callback Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_2100",
0,
async function (done) {
await asyCallback
.signAndVerifyNormalProcessSuperdata(
"RSA3072",
"RSA3072|PKCS1|SHA224",
"350"
)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_2100 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_1500
* @tc.name Test createVerify interface with invalid input
* @tc.desc First input RSA4096|NULL|SHA256, Second input RSA4096|PKCS1|NULL
* @tc.desc Third input RSA4096|PKCS1|SHA122, Fourth input RSA4096|PKCS5|SHA256
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_1500",
0,
async function (done) {
try {
let rsaGenerator = cryptoFramework.createAsyKeyGenerator("RSA3072");
await rsaGenerator.generateKeyPair();
cryptoFramework.createVerify("RSA4096|NULL|SHA256");
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
cryptoFramework.createVerify("RSA4096|PKCS1|NULL");
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
cryptoFramework.createVerify("RSA4096|PKCS1|SHA122");
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
cryptoFramework.createVerify("RSA4096|PKCS5|SHA256");
} catch (err) {
expect(err.code).assertEqual(401);
}
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0100
* @tc.name Test ECC224|SHA256 normal sign and verify
* @tc.desc Use the Callback Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0100",
0,
async function (done) {
await asyCallback
.signAndVerifyNormalProcess("ECC224", "ECC224|SHA256")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0100 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0200
* @tc.name Test ECC256|SHA1 normal sign and verify
* @tc.desc Use the Promise Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0200",
0,
async function (done) {
await asyPromise
.signAndVerifyNormalProcess("ECC256", "ECC256|SHA1")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0200 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0300
* @tc.name Test ECC224|SHA256 normal sign and verify
* @tc.desc Use the Callback Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0300",
0,
async function (done) {
await asyCallback
.signAndVerifyNormalProcess("ECC384", "ECC384|SHA224")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0300 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0400
* @tc.name Test ECC521|SHA384 normal sign and verify
* @tc.desc Use the Callback Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0400",
0,
async function (done) {
await asyPromise
.signAndVerifyNormalProcess("ECC521", "ECC521|SHA384")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0400 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0500
* @tc.name Test ECC224|SHA512 normal sign and verify
* @tc.desc Use the Callback Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0500",
0,
async function (done) {
await asyPromise
.signAndVerifyNormalProcess("ECC224", "ECC224|SHA512")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0500 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0600
* @tc.name Test createAsyKeyGenerator interface with invalid input
* @tc.desc First input ECC1, Second input null character string
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0600",
0,
async function (done) {
try {
cryptoFramework.createAsyKeyGenerator("ECC1");
} catch (err) {
console.error("err is:" + err.code);
expect(err.code).assertEqual(401);
}
try {
cryptoFramework.createAsyKeyGenerator("");
} catch (err) {
console.error("err is:" + err.code);
expect(err.code).assertEqual(401);
}
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0700
* @tc.name Test createSign with invalid input
* @tc.desc First input ECC224|SHA257, Second input ECC224|NULL
* @tc.desc Third input NULL|SHA1, Fourth input ECC1|SHA1
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0700",
0,
async function (done) {
try {
let rsaGenerator = cryptoFramework.createAsyKeyGenerator("ECC224");
await rsaGenerator.generateKeyPair();
cryptoFramework.createSign("ECC224|SHA257");
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
cryptoFramework.createSign("ECC224|NULL");
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
cryptoFramework.createSign("NULL|SHA1");
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
cryptoFramework.createSign("ECC1|SHA1");
} catch (err) {
expect(err.code).assertEqual(401);
}
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0800
* @tc.name Test createVerify with invalid input
* @tc.desc First input ECC1|SHA256, Second input NULL|SHA256
* @tc.desc Third input ECC224|SHA122, Fourth input ECC224|NULL
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0800",
0,
async function (done) {
try {
cryptoFramework.createAsyKeyGenerator("RSA3072");
cryptoFramework.createVerify("ECC1|SHA256");
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
cryptoFramework.createVerify("NULL|SHA256");
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
cryptoFramework.createVerify("ECC224|SHA122");
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
cryptoFramework.createVerify("ECC224|NULL");
} catch (err) {
expect(err.code).assertEqual(401);
}
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0900
* @tc.name Test ECC224|SHA512 normal sign and verify
* @tc.desc Use the Callback Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0900",
0,
async function (done) {
await asyCallback
.signAndVerifyNormalProcessSuperdata(
"ECC224",
"ECC224|SHA512",
"350"
)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_ECDSA_0900 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_ECDH_0100
* @tc.name Test ECC224 SignVerify ECDH
* @tc.desc Use the Promise Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_ECDH_0100",
0,
async function (done) {
await asyPromise
.keyAgreementProcess("ECC224")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_ECDH_0100 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_ECDH_0200
* @tc.name Test ECC256 SignVerify ECDH
* @tc.desc Use the Callback Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_ECDH_0200",
0,
async function (done) {
await asyCallback
.keyAgreementProcess("ECC256")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_ECDH_0200 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_ECDH_0300
* @tc.name Test ECC384 SignVerify ECDH
* @tc.desc Use the Promise Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_ECDH_0300",
0,
async function (done) {
await asyPromise
.keyAgreementProcess("ECC384")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_ECDH_0300 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_ECDH_0400
* @tc.name Test ECC521 SignVerify ECDH
* @tc.desc Use the Callback Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_ECDH_0400",
0,
async function (done) {
await asyCallback
.keyAgreementProcess("ECC521")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_ECDH_0400 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_ECDH_0500
* @tc.name Test createKeyAgreement with invalid input
* @tc.desc First input ECC5, Second input NULL
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_ECDH_0500",
0,
async function (done) {
try {
cryptoFramework.createKeyAgreement("ECC5");
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
cryptoFramework.createKeyAgreement(null);
} catch (err) {
expect(err.code).assertEqual(401);
}
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_ECDH_0600
* @tc.name Test generateSecret of KeyAgreement with invalid input 1
* @tc.desc First input invalid pubkey, Second input invalide prikey
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_ECDH_0600",
0,
async function (done) {
let rsaGenerator = cryptoFramework.createAsyKeyGenerator("ECC256");
let keyPair1 = await rsaGenerator.generateKeyPair();
expect(keyPair1 != null).assertTrue();
let keyPair2 = await new Promise((resolve, reject) => {
rsaGenerator.generateKeyPair((err, keyPair) => {
if (err) {
reject(err);
} else {
resolve(keyPair);
}
})
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_Encryption_RSA_3100 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_1100
* @tc.name Test RSA2048|PSS|SHA1|MGF1_SHA1 normal sign and verify
* @tc.desc Use the Promise Style of Interface
*/
expect(keyPair2 != null).assertTrue();
let keyAgrementGenerator = cryptoFramework.createKeyAgreement("ECC256");
try {
await keyAgrementGenerator.generateSecret(null, null);
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
await new Promise((resolve, reject) => {
keyAgrementGenerator.generateSecret(keyPair1.priKey, null, (err, data) => {
if (err) {
reject(err);
} else {
resolve(data);
}
})
})
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
await keyAgrementGenerator.generateSecret(null, keyPair2.pubKey)
} catch (err) {
expect(err.code).assertEqual(401);
}
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_ECDH_0700
* @tc.name Test generateSecret of KeyAgreement with invalid input 2
* @tc.desc The public key and private key do not match
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_1100",
0,
async function (done) {
await asyPromise
.signAndVerifyNormalProcess("RSA8192", "RSA8192|PSS|SHA512|MGF1_SHA512")
.then((data) => {
expect(data == null).assertTrue();
"Security_crypto_framework_ASymmetric_SignVerify_ECDH_0700",
0,
async function (done) {
let rsaGenerator = cryptoFramework.createAsyKeyGenerator("RSA3072");
let keyPair1 = await rsaGenerator.generateKeyPair();
expect(keyPair1 != null).assertTrue();
let keyPair2 = await new Promise((resolve, reject) => {
rsaGenerator.generateKeyPair((err, keyPair) => {
if (err) {
reject(err);
} else {
resolve(keyPair);
}
})
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_1100 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
});
expect(keyPair2 != null).assertTrue();
let keyAgrementGenerator = cryptoFramework.createKeyAgreement("ECC521");
try {
await keyAgrementGenerator.generateSecret(keyPair1.prikey, keyPair2.pubKey)
} catch (err) {
expect(err.code).assertEqual(401);
}
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_Encryption_RSA_3300
* @tc.name Test convertKey
* @tc.desc Use RSA3072|PRIMES_2 algorithm
*/
it(
"Security_crypto_framework_ASymmetric_Encryption_RSA_3300",
0,
async function (done) {
await asyPromise
.convertKeyEncryptAndDecryptProcess("RSA3072|PRIMES_2")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_Encryption_RSA_3300 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_Encryption_RSA_3100
* @tc.name Test convertKey
* @tc.desc Use RSA1024|PRIMES_2 algorithm
*/
it(
"Security_crypto_framework_ASymmetric_Encryption_RSA_3100",
0,
async function (done) {
await asyPromise
.AsyPriKeyClearProcess("RSA1024|PRIMES_2")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_Encryption_RSA_3100 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_ASymmetric_SignVerify_RSA_1100
* @tc.name Test RSA2048|PSS|SHA1|MGF1_SHA1 normal sign and verify
* @tc.desc Use the Promise Style of Interface
*/
it(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_1100",
0,
async function (done) {
await asyPromise
.signAndVerifyNormalProcess("RSA8192", "RSA8192|PSS|SHA512|MGF1_SHA512")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_ASymmetric_SignVerify_RSA_1100 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
});
}
......@@ -15,331 +15,351 @@
import { describe, beforeAll, afterEach, it, expect } from "@ohos/hypium";
import {
testHMACDigestPromise,
testMDDigestPromise,
testHMACErrorAlgorithm,
testHMACDigestPromiseErrorKey,
testHMACDigestPromiseDatablobNull,
testHMACDigestPromiseDatablobLong,
testHMACDigestPromise,
testMDDigestPromise,
testHMACErrorAlgorithm,
testHMACDigestPromiseErrorKey,
testHMACDigestPromiseDatablobNull,
testHMACDigestPromiseDatablobLong,
} from "./utils/digestalgorithm/publicDigestPromise";
import {
testHMACDigestCallback,
testMDDigestCallback,
testMDErrorAlgorithm,
testMDErrorAlgorithmNull,
testMDDigestCallbackLen,
testMDDigestCallbackLenNull,
testHMACDigestCallback,
testMDDigestCallback,
testMDErrorAlgorithm,
testMDErrorAlgorithmNull,
testMDDigestCallbackLen,
} from "./utils/digestalgorithm/publicDigestCallback";
import cryptoFramework from "@ohos.security.cryptoFramework";
export default function DigestAlgorithmJsunit() {
describe("DigestAlgorithmJsunit", function () {
console.info("##########start DigestAlgorithmJsunit##########");
beforeAll(function () {});
afterEach(function () {});
describe("DigestAlgorithmJsunit", function () {
console.info("##########start DigestAlgorithmJsunit##########");
beforeAll(function () {
});
afterEach(function () {
});
/**
* @tc.number Security_crypto_framework_MD_0100
* @tc.name Test MD5 for MD digest algotithm
* @tc.desc Use the Promise Style of Interface
*/
it("Security_crypto_framework_MD_0100", 0, async function (done) {
await testMDDigestPromise("MD5")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
/**
* @tc.number Security_crypto_framework_MD_0100
* @tc.name Test MD5 for MD digest algotithm
* @tc.desc Use the Promise Style of Interface
*/
it("Security_crypto_framework_MD_0100", 0, async function (done) {
await testMDDigestPromise("MD5")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
});
done();
});
done();
});
/**
* @tc.number Security_crypto_framework_MD_0200
* @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) {
await testMDDigestPromise("SHA1")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
/**
* @tc.number Security_crypto_framework_MD_0200
* @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) {
await testMDDigestPromise("SHA1")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
});
done();
});
done();
});
/**
* @tc.number Security_crypto_framework_MD_0300
* @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) {
await testMDDigestPromise("SHA224")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
/**
* @tc.number Security_crypto_framework_MD_0300
* @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) {
await testMDDigestPromise("SHA224")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
});
done();
});
done();
});
/**
* @tc.number Security_crypto_framework_MD_0400
* @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) {
await testMDDigestCallback("SHA256")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
/**
* @tc.number Security_crypto_framework_MD_0400
* @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) {
await testMDDigestCallback("SHA256")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
});
done();
});
done();
});
/**
* @tc.number Security_crypto_framework_MD_0500
*
* @tc.name Test SHA384 for MD digest algotithm
* @tc.desc Use the Callback Style of Interface
*/
it("Security_crypto_framework_MD_0500", 0, async function (done) {
await testMDDigestCallback("SHA384")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
/**
* @tc.number Security_crypto_framework_MD_0500
*
* @tc.name Test SHA384 for MD digest algotithm
* @tc.desc Use the Callback Style of Interface
*/
it("Security_crypto_framework_MD_0500", 0, async function (done) {
await testMDDigestCallback("SHA384")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
});
done();
});
done();
});
/**
* @tc.number Security_crypto_framework_MD_0600
* @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) {
await testMDDigestCallback("SHA512")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
/**
* @tc.number Security_crypto_framework_MD_0600
* @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) {
await testMDDigestCallback("SHA512")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
});
done();
});
done();
});
/**
* @tc.number Security_crypto_framework_MD_0700
* @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) {
await testMDErrorAlgorithm("SHA5")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
/**
* @tc.number Security_crypto_framework_MD_0700
* @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) {
await testMDErrorAlgorithm("SHA5")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
});
done();
});
done();
});
/**
* @tc.number Security_crypto_framework_MD_0800
* @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) {
await testMDErrorAlgorithmNull(null)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
/**
* @tc.number Security_crypto_framework_MD_0800
* @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) {
await testMDErrorAlgorithmNull(null)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
});
done();
});
done();
});
/**
* @tc.number Security_crypto_framework_MD_0900
* @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) {
await testMDDigestCallbackLen("SHA224", 10000)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
/**
* @tc.number Security_crypto_framework_MD_0900
* @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) {
await testMDDigestCallbackLen("SHA224", 10000)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
});
done();
});
done();
});
/**
* @tc.number Security_crypto_framework_MD_1000
* @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) {
await testMDDigestCallbackLenNull("SHA224")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
/**
* @tc.number Security_crypto_framework_MD_1000
* @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) {
let mdGenerator = cryptoFramework.createMd("SHA224");
try {
await new Promise((resolve, reject) => {
mdGenerator.update(null, (err,) => {
if (err) {
reject(err);
} else {
resolve();
}
})
})
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
await mdGenerator.update(0);
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
await mdGenerator.digest();
} catch (err) {
console.error("1111111 " + err.code);
}
done();
});
done();
});
/**
* @tc.number Security_crypto_framework_HMAC_0100
* @tc.name Test SHA1 for HMAC digest algorithm
* @tc.desc Use the Callback Style of Interface
*/
it("Security_crypto_framework_HMAC_0100", 0, async function (done) {
await testHMACDigestCallback("SHA1", "AES128")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
/**
* @tc.number Security_crypto_framework_HMAC_0100
* @tc.name Test SHA1 for HMAC digest algorithm
* @tc.desc Use the Callback Style of Interface
*/
it("Security_crypto_framework_HMAC_0100", 0, async function (done) {
await testHMACDigestCallback("SHA1", "AES128")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
});
done();
});
done();
});
/**
* @tc.number Security_crypto_framework_HMAC_0200
* @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) {
await testHMACDigestPromise("SHA224", "AES192")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
/**
* @tc.number Security_crypto_framework_HMAC_0200
* @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) {
await testHMACDigestPromise("SHA224", "AES192")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
});
done();
});
done();
});
/**
* @tc.number Security_crypto_framework_HMAC_0300
* @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) {
await testHMACDigestCallback("SHA256", "AES256")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
/**
* @tc.number Security_crypto_framework_HMAC_0300
* @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) {
await testHMACDigestCallback("SHA256", "AES256")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
});
done();
});
done();
});
/**
* @tc.number Security_crypto_framework_HMAC_0400
* @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) {
await testHMACDigestPromise("SHA384", "3DES192")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
/**
* @tc.number Security_crypto_framework_HMAC_0400
* @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) {
await testHMACDigestPromise("SHA384", "3DES192")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
});
done();
});
done();
});
/**
* @tc.number Security_crypto_framework_HMAC_0500
* @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) {
await testHMACDigestPromise("SHA512", "3DES192")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
/**
* @tc.number Security_crypto_framework_HMAC_0500
* @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) {
await testHMACDigestPromise("SHA512", "3DES192")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
});
done();
});
done();
});
/**
* @tc.number Security_crypto_framework_HMAC_0600
* @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) {
await testHMACErrorAlgorithm("SHA5", null)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
/**
* @tc.number Security_crypto_framework_HMAC_0600
* @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) {
await testHMACErrorAlgorithm("SHA5", null)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
});
done();
});
done();
});
/**
* @tc.number Security_crypto_framework_HMAC_0700
* @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) {
await testHMACDigestPromiseErrorKey("SHA512", "RSA1024|PRIMES_2")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
/**
* @tc.number Security_crypto_framework_HMAC_0700
* @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) {
await testHMACDigestPromiseErrorKey("SHA512", "RSA1024|PRIMES_2")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
});
done();
});
done();
});
/**
* @tc.number Security_crypto_framework_HMAC_0800
* @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) {
await testHMACDigestPromiseDatablobNull("SHA512", "3DES192")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
/**
* @tc.number Security_crypto_framework_HMAC_0800
* @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) {
await testHMACDigestPromiseDatablobNull("SHA512", "3DES192")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
});
done();
});
done();
});
/**
* @tc.number Security_crypto_framework_HMAC_0900
* @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) {
await testHMACDigestPromiseDatablobLong("SHA512", "3DES192", 10000)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
/**
* @tc.number Security_crypto_framework_HMAC_0900
* @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) {
await testHMACDigestPromiseDatablobLong("SHA512", "3DES192", 10000)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
});
done();
});
done();
});
});
}
......@@ -13,16 +13,16 @@
* limitations under the License.
*/
import SymmetricCryptographyJsunit from "./SymmetricCryptography.test";
import AsymmetricCryptographyJsunit from "./AsymmetricCryptography.test";
import AsymmetricCryptographyJsSecondunit from "./AsymmetricCryptographySecond.test";
import DigestAlgorithmJsunit from "./DigestAlgorithm.test";
import SecurityRandomJsunit from "./SecurityRandom.test";
import SymmetricCryptographyJsunit from './SymmetricCryptography.test';
import AsymmetricCryptographyJsunit from './AsymmetricCryptography.test';
import AsymmetricCryptographyJsSecondunit from './AsymmetricCryptographySecond.test';
import DigestAlgorithmJsunit from './DigestAlgorithm.test';
import SecurityRandomJsunit from './SecurityRandom.test';
export default function testsuite() {
SymmetricCryptographyJsunit();
AsymmetricCryptographyJsunit();
AsymmetricCryptographyJsSecondunit();
DigestAlgorithmJsunit();
SecurityRandomJsunit();
SymmetricCryptographyJsunit();
AsymmetricCryptographyJsunit();
AsymmetricCryptographyJsSecondunit();
DigestAlgorithmJsunit();
SecurityRandomJsunit();
}
......@@ -16,126 +16,124 @@
import { describe, beforeAll, afterEach, it, expect } from "@ohos/hypium";
import { testSecurityRandomPromise } from "./utils/securityrandom/publicSecurityRandomPromise";
import {
testSecurityRandomCallback,
testSecurityRandomLengthCallback,
testSecurityRandomCallbackSeed,
} from "./utils/securityrandom/publicSecurityRandomCallback";
import { testSecurityRandomCallback } from "./utils/securityrandom/publicSecurityRandomCallback";
import { testSecurityRandomEnumCommon } from "./utils/securityrandom/publicSecurityRandomCommon";
import cryptoFramework from "@ohos.security.cryptoFramework";
export default function SecurityRandomJsunit() {
describe("SecurityRandomJsunit", function () {
console.info("##########start SecurityRandomJsunit##########");
beforeAll(function () {});
afterEach(function () {});
/**
* @tc.number Security_crypto_framework_Random_0100
* @tc.name support security random and set random seed
* @tc.desc the length of random is 32, use promise style of interface
*/
it("Security_crypto_framework_Random_0100", 0, async function (done) {
await testSecurityRandomPromise(32)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
describe("SecurityRandomJsunit", function () {
console.info("##########start SecurityRandomJsunit##########");
beforeAll(function () {
});
done();
});
/**
* @tc.number Security_crypto_framework_Random_0200
* @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) {
await testSecurityRandomCallback(32)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
afterEach(function () {
});
done();
});
/**
* @tc.number Security_crypto_framework_Random_0300
* @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)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
});
await testSecurityRandomLengthCallback(null)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
});
await testSecurityRandomLengthCallback(-1)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
/**
* @tc.number Security_crypto_framework_Random_0100
* @tc.name support security random and set random seed
* @tc.desc the length of random is 32, use promise style of interface
*/
it("Security_crypto_framework_Random_0100", 0, async function (done) {
await testSecurityRandomPromise(32)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
});
done();
});
await testSecurityRandomLengthCallback(2147483647)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
});
done();
});
/**
* @tc.number Security_crypto_framework_Random_0400
* @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)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
/**
* @tc.number Security_crypto_framework_Random_0200
* @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) {
await testSecurityRandomCallback(32)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
});
done();
});
await testSecurityRandomCallbackSeed(0)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
/**
* @tc.number Security_crypto_framework_Random_0300
* @tc.name Test generateRandom with invalid input
* @tc.desc First input 0, Second input null, Third input -1, Fourth input 2147483648
*/
it("Security_crypto_framework_Random_0300", 0, async function (done) {
let randomGenerator = cryptoFramework.createRandom();
try {
await new Promise((resolve, reject) => {
randomGenerator.generateRandom(0, (err, dataBlob) => {
if (err) {
reject(err);
} else {
resolve(dataBlob);
}
})
})
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
await randomGenerator.generateRandom(null);
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
await new Promise((resolve, reject) => {
randomGenerator.generateRandom(-1, (err, dataBlob) => {
if (err) {
reject(err);
} else {
resolve(dataBlob);
}
})
})
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
await randomGenerator.generateRandom(2147483648);
} catch (err) {
expect(err.code).assertEqual(401);
}
done();
});
await testSecurityRandomCallbackSeed(2147483647)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
expect(null).assertFail();
/**
* @tc.number Security_crypto_framework_Random_0400
* @tc.name Test setSeed with invalid input
* @tc.desc First input null, Second input 0
*/
it("Security_crypto_framework_Random_0400", 0, async function (done) {
let randomGenerator = cryptoFramework.createRandom();
try {
randomGenerator.setSeed(null);
} catch (err) {
expect(err.code).assertEqual(401);
}
try {
randomGenerator.setSeed(0);
} catch (err) {
expect(err.code).assertEqual(401);
}
done();
});
done();
});
/**
* @tc.number Security_crypto_framework_Random_0500
* @tc.name test enumerated values
* @tc.desc cover 100% Enumerated values
*/
it("Security_crypto_framework_Random_0500", 0, async function (done) {
testSecurityRandomEnumCommon();
done();
/**
* @tc.number Security_crypto_framework_Random_0500
* @tc.name test enumerated values
* @tc.desc cover 100% Enumerated values
*/
it("Security_crypto_framework_Random_0500", 0, async function (done) {
testSecurityRandomEnumCommon();
done();
});
});
});
}
......@@ -18,1001 +18,1003 @@ import * as symPromise from "./utils/symmetric/publicSymmetricPromise";
import * as symCallback from "./utils/symmetric/publicSymmetricCallback";
export default function SymmetricCryptographyJsunit() {
describe("SymmetricCryptographyJsunit", function () {
console.info("##########start SymmetricCryptographyJsunit##########");
beforeAll(function () {});
afterEach(function () {});
/**
* @tc.number Security_crypto_framework_Symmetric_Encryption_AES_0100
* @tc.name Test AES128|GCM|PKCS7 normal encryption and decryption
* @tc.desc Use the Callback Style of Interface
*/
it(
"Security_crypto_framework_Symmetric_Encryption_AES_0100",
0,
async function (done) {
await symCallback
.encryptAndDecryptNormalProcess(
"AES128",
"AES128|GCM|PKCS7",
"genGcmParamsSpec"
)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_Symmetric_Encryption_AES_0100 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @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",
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(
"3DES192",
"3DES192|CFB|PKCS7",
"genIvParamsSpec"
)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"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();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_Symmetric_Encryption_AES_2100
* @tc.name Test AES128|GCM|PKCS7 convertKey encryption and decryption
* @tc.desc Use the Callback Style of Interface
*/
it(
"Security_crypto_framework_Symmetric_Encryption_AES_2100",
0,
async function (done) {
await symCallback
.convertKeyEncryptAndDecryptProcess(
"AES128",
"AES128|GCM|PKCS7",
"genGcmParamsSpec"
)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_Symmetric_Encryption_AES_2100 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @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
* @tc.desc Use the Promise Style of Interface
*/
it(
"Security_crypto_framework_Symmetric_Encryption_AES_2300",
0,
async function (done) {
await symPromise
.convertKeyEncryptAndDecryptProcess(
"AES256",
"AES256|GCM|PKCS7",
"genGcmParamsSpec"
)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_Symmetric_Encryption_AES_2300 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @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
* @tc.desc Use the Promise Style of Interface
*/
it(
"Security_crypto_framework_Symmetric_Encryption_AES_3700",
0,
async function (done) {
await symPromise
.ClearMemProcess("AES256")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_Symmetric_Encryption_AES_3700 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
});
describe("SymmetricCryptographyJsunit", function () {
console.info("##########start SymmetricCryptographyJsunit##########");
beforeAll(function () {
});
afterEach(function () {
});
/**
* @tc.number Security_crypto_framework_Symmetric_Encryption_AES_0100
* @tc.name Test AES128|GCM|PKCS7 normal encryption and decryption
* @tc.desc Use the Callback Style of Interface
*/
it(
"Security_crypto_framework_Symmetric_Encryption_AES_0100",
0,
async function (done) {
await symCallback
.encryptAndDecryptNormalProcess(
"AES128",
"AES128|GCM|PKCS7",
"genGcmParamsSpec"
)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_Symmetric_Encryption_AES_0100 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @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",
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(
"3DES192",
"3DES192|CFB|PKCS7",
"genIvParamsSpec"
)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"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();
});
done();
}
);
/**
* @tc.number Security_crypto_framework_Symmetric_Encryption_AES_2100
* @tc.name Test AES128|GCM|PKCS7 convertKey encryption and decryption
* @tc.desc Use the Callback Style of Interface
*/
it(
"Security_crypto_framework_Symmetric_Encryption_AES_2100",
0,
async function (done) {
await symCallback
.convertKeyEncryptAndDecryptProcess(
"AES128",
"AES128|GCM|PKCS7",
"genGcmParamsSpec"
)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_Symmetric_Encryption_AES_2100 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @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
* @tc.desc Use the Promise Style of Interface
*/
it(
"Security_crypto_framework_Symmetric_Encryption_AES_2300",
0,
async function (done) {
await symPromise
.convertKeyEncryptAndDecryptProcess(
"AES256",
"AES256|GCM|PKCS7",
"genGcmParamsSpec"
)
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_Symmetric_Encryption_AES_2300 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
/**
* @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
* @tc.desc Use the Promise Style of Interface
*/
it(
"Security_crypto_framework_Symmetric_Encryption_AES_3700",
0,
async function (done) {
await symPromise
.ClearMemProcess("AES256")
.then((data) => {
expect(data == null).assertTrue();
})
.catch((err) => {
console.error(
"Security_crypto_framework_Symmetric_Encryption_AES_3700 catch error: " +
err
);
expect(null).assertFail();
});
done();
}
);
});
}
......@@ -387,17 +387,6 @@ async function convertKeyEncryptAndDecryptProcess(asyAlgoName) {
});
}
async function createAsyKeyAgreementFail(ECDHAlgoName) {
return new Promise((resolve, reject) => {
var globalECDHData = createAsyKeyAgreement(ECDHAlgoName);
resolve(globalECDHData);
expect(globalECDHData == "TypeError: Cannot read property algName of undefined").assertTrue();
if (globalECDHData != "TypeError: Cannot read property algName of undefined"){
reject();
}
});
}
async function keyAgreementProcess(ECDHAlgoName) {
var globalRsaKeyPair;
......@@ -425,98 +414,6 @@ async function keyAgreementProcess(ECDHAlgoName) {
});
}
async function keyAgreementProcessFail(ECDHAlgoName, ECDHAlgoName1) {
var globalRsaKeyPair;
return new Promise((resolve, reject) => {
var rsaGenerator = createAsyKeyGenerator(ECDHAlgoName);
expect(rsaGenerator != null).assertTrue();
var globalECDHData = createAsyKeyAgreement(ECDHAlgoName1);
expect(globalECDHData != null).assertTrue();
generateAsyKeyPair(rsaGenerator)
.then((rsaKeyPair) => {
expect(rsaKeyPair != null).assertTrue();
globalRsaKeyPair = rsaKeyPair;
return generateAsySecret(globalECDHData, globalRsaKeyPair.priKey, globalRsaKeyPair.pubKey);
})
.then((result) => {
console.warn("result data is " + uInt8ArrayToShowStr(result.data));
expect(result != null).assertTrue();
reject();
})
.catch((err) => {
console.error("[Callback] keyAgreementProcess catch err:" + err);
resolve(err);
});
});
}
async function keyAgreementProcessParameterException(ECDHAlgoName) {
var globalRsaKeyPair;
return new Promise((resolve, reject) => {
var rsaGenerator = createAsyKeyGenerator(ECDHAlgoName);
expect(rsaGenerator != null).assertTrue();
var globalECDHData = createAsyKeyAgreement(ECDHAlgoName);
expect(globalECDHData != null).assertTrue();
generateAsyKeyPair(rsaGenerator)
.then((rsaKeyPair) => {
expect(rsaKeyPair != null).assertTrue();
globalRsaKeyPair = rsaKeyPair;
return generateAsySecret(globalECDHData, null, null);
})
.then((result) => {
console.warn("result data is " + uInt8ArrayToShowStr(result.data));
expect(result != null).assertTrue();
})
.catch((err) => {
expect(err == "Error: [PriKey]: param unwarp error.").assertTrue();
});
generateAsyKeyPair(rsaGenerator)
.then((rsaKeyPair) => {
expect(rsaKeyPair != null).assertTrue();
globalRsaKeyPair = rsaKeyPair;
return generateAsySecret(globalECDHData, globalRsaKeyPair.pubKey, null);
})
.then((result) => {
console.warn("result data is " + uInt8ArrayToShowStr(result.data));
expect(result != null).assertTrue();
})
.catch((err) => {
expect(err == "Error: [PubKey]: param unwarp error.").assertTrue();
});
generateAsyKeyPair(rsaGenerator)
.then((rsaKeyPair) => {
expect(rsaKeyPair != null).assertTrue();
globalRsaKeyPair = rsaKeyPair;
return generateAsySecret(globalECDHData, null, globalRsaKeyPair.priKey);
})
.then((result) => {
console.warn("result data is " + uInt8ArrayToShowStr(result.data));
expect(result != null).assertTrue();
reject();
})
.catch((err) => {
expect(err == "Error: [PriKey]: param unwarp error.").assertTrue();
resolve(err);
});
});
}
async function createAsyKeyGeneratorFail(asyAlgoName) {
return new Promise((resolve, reject) => {
var rsaGenerator = createAsyKeyGenerator(asyAlgoName);
resolve(rsaGenerator);
expect(rsaGenerator == "TypeError: Cannot read property algName of null").assertTrue();
if (rsaGenerator != "TypeError: Cannot read property algName of null") {
reject();
}
});
}
async function encryptAndDecryptNormalProcessSuperdata(asyAlgoName, cipherAlgoName, globalTextLen) {
var globalCipherText;
var globalRsaKeyPair;
......@@ -714,7 +611,6 @@ async function encryptAndDecryptNormalProcessNull(asyAlgoName, cipherAlgoName) {
);
}
let decryptData = uInt8ArrayToString(finalOutput.data);
expect(decryptData == globalText).assertTrue();
reject();
})
.catch((err) => {
......@@ -730,11 +626,7 @@ export {
signAndVerifyNormalProcess,
convertKeyEncryptAndDecryptProcess,
keyAgreementProcess,
createAsyKeyAgreementFail,
keyAgreementProcessFail,
keyAgreementProcessParameterException,
createAsyKeyGeneratorFail,
encryptAndDecryptNormalProcessSuperdata,
signAndVerifyNormalProcessSuperdata,
encryptAndDecryptNormalProcessNull,
encryptAndDecryptNormalProcessNull
};
......@@ -15,574 +15,487 @@
import { expect } from "@ohos/hypium";
import cryptoFramework from "@ohos.security.cryptoFramework";
import { stringTouInt8Array, uInt8ArrayToShowStr, uInt8ArrayToString, } from "../common/publicDoString";
import {
stringTouInt8Array,
uInt8ArrayToShowStr,
uInt8ArrayToString,
} from "../common/publicDoString";
import {
createAsyKeyGenerator,
createAsyCipher,
createAsySign,
createAsyVerify,
createAsyKeyAgreement,
createAsyKeyGenerator,
createAsyCipher,
createAsySign,
createAsyVerify,
createAsyKeyAgreement,
} from "./publicAsymmetricCommon";
async function generateAsyKeyPair(rsaGenerator) {
var pubKey;
var priKey;
return new Promise((resolve, reject) => {
rsaGenerator
.generateKeyPair()
.then((rsaKeyPair) => {
pubKey = rsaKeyPair.pubKey;
let encodedPubKey = pubKey.getEncoded();
console.log("[Promise]: pubKey.getAlgorithm= " + pubKey.algName);
console.log("[Promise]: pubKey.getEncoded= " + encodedPubKey.data);
console.log("[Promise]: pubKey.getFormat= " + pubKey.format);
priKey = rsaKeyPair.priKey;
let encodedPriKey = priKey.getEncoded();
console.log("[Promise]: priKey.getAlgorithm= " + priKey.algName);
console.log("[Promise]: priKey.getEncoded= " + encodedPriKey.data);
console.log("[Promise]: priKey.getFormat= " + priKey.format);
resolve(rsaKeyPair);
})
.catch((err) => {
console.error("[Promise]generateSymKey failed. error is " + err);
reject(err);
});
});
var pubKey;
var priKey;
return new Promise((resolve, reject) => {
rsaGenerator
.generateKeyPair()
.then((rsaKeyPair) => {
pubKey = rsaKeyPair.pubKey;
let encodedPubKey = pubKey.getEncoded();
console.log("[Promise]: pubKey.getAlgorithm= " + pubKey.algName);
console.log("[Promise]: pubKey.getEncoded= " + encodedPubKey.data);
console.log("[Promise]: pubKey.getFormat= " + pubKey.format);
priKey = rsaKeyPair.priKey;
let encodedPriKey = priKey.getEncoded();
console.log("[Promise]: priKey.getAlgorithm= " + priKey.algName);
console.log("[Promise]: priKey.getEncoded= " + encodedPriKey.data);
console.log("[Promise]: priKey.getFormat= " + priKey.format);
resolve(rsaKeyPair);
})
.catch((err) => {
console.error("[Promise]generateSymKey failed. error is " + err);
reject(err);
});
});
}
async function convertAsyKey(rsaGenerator, pubKeyDataBlob, priKeyDataBlob) {
return new Promise((resolve, reject) => {
rsaGenerator
.convertKey(pubKeyDataBlob, priKeyDataBlob)
.then((convertKeyPair) => {
console.log(
"[Promise]convertKey success. convertKeyPair is " + convertKeyPair
);
resolve(convertKeyPair);
})
.catch((err) => {
console.error("[Promise]convertKey failed. error is " + err);
reject(err);
});
});
return new Promise((resolve, reject) => {
rsaGenerator
.convertKey(pubKeyDataBlob, priKeyDataBlob)
.then((convertKeyPair) => {
console.log(
"[Promise]convertKey success. convertKeyPair is " + convertKeyPair
);
resolve(convertKeyPair);
})
.catch((err) => {
console.error("[Promise]convertKey failed. error is " + err);
reject(err);
});
});
}
async function initCipher(cipherGenerator, mode, key, params) {
return new Promise((resolve, reject) => {
cipherGenerator
.init(mode, key, params)
.then(() => {
console.log("[Promise]cipherGenerator init success! mode is : " + mode);
resolve("init success");
})
.catch((err) => {
console.error(
"[Promise]cipherGenerator init failed. error is " +
err +
"mode is " +
mode
);
reject(err);
});
});
return new Promise((resolve, reject) => {
cipherGenerator
.init(mode, key, params)
.then(() => {
console.log("[Promise]cipherGenerator init success! mode is : " + mode);
resolve("init success");
})
.catch((err) => {
console.error(
"[Promise]cipherGenerator init failed. error is " +
err +
"mode is " +
mode
);
reject(err);
});
});
}
async function doFinalCipher(cipherGenerator, mode, dataBlob) {
return new Promise((resolve, reject) => {
cipherGenerator
.doFinal(dataBlob)
.then((finalData) => {
console.log(
"[Promise]cipherGenerator doFinal success! mode is : " + mode
);
resolve(finalData);
})
.catch((err) => {
console.error(
"[Promise]cipherGenerator doFinal failed. error is " +
err +
"mode is " +
mode
);
reject(err);
});
});
return new Promise((resolve, reject) => {
cipherGenerator
.doFinal(dataBlob)
.then((finalData) => {
console.log(
"[Promise]cipherGenerator doFinal success! mode is : " + mode
);
resolve(finalData);
})
.catch((err) => {
console.error(
"[Promise]cipherGenerator doFinal failed. error is " +
err +
"mode is " +
mode
);
reject(err);
});
});
}
async function initSign(signGenerator, priKey) {
return new Promise((resolve, reject) => {
signGenerator
.init(priKey)
.then(() => {
console.log("[Promise]signGenerator init success!");
resolve("init success");
})
.catch((err) => {
console.error("[Promise]signGenerator init failed. error is " + err);
reject(err);
});
});
return new Promise((resolve, reject) => {
signGenerator
.init(priKey)
.then(() => {
console.log("[Promise]signGenerator init success!");
resolve("init success");
})
.catch((err) => {
console.error("[Promise]signGenerator init failed. error is " + err);
reject(err);
});
});
}
async function updateSign(signGenerator, dataBlob) {
return new Promise((resolve, reject) => {
signGenerator
.update(dataBlob)
.then(() => {
console.log("[Promise]signGenerator update success!");
resolve("update success");
})
.catch((err) => {
console.error("[Promise]signGenerator update failed. error is " + err);
reject(err);
});
});
return new Promise((resolve, reject) => {
signGenerator
.update(dataBlob)
.then(() => {
console.log("[Promise]signGenerator update success!");
resolve("update success");
})
.catch((err) => {
console.error("[Promise]signGenerator update failed. error is " + err);
reject(err);
});
});
}
async function signForSign(signGenerator, dataBlob) {
return new Promise((resolve, reject) => {
signGenerator
.sign(dataBlob)
.then((signOutput) => {
console.log("[Promise]signGenerator sign success!");
resolve(signOutput);
})
.catch((err) => {
console.error("[Promise]signGenerator sign failed. error is " + err);
reject(err);
});
});
return new Promise((resolve, reject) => {
signGenerator
.sign(dataBlob)
.then((signOutput) => {
console.log("[Promise]signGenerator sign success!");
resolve(signOutput);
})
.catch((err) => {
console.error("[Promise]signGenerator sign failed. error is " + err);
reject(err);
});
});
}
async function initVerify(verifyGenerator, pubKey) {
return new Promise((resolve, reject) => {
verifyGenerator
.init(pubKey)
.then(() => {
console.log("[Promise]verifyGenerator init success!");
resolve("init success");
})
.catch((err) => {
console.error("[Promise]verifyGenerator init failed. error is " + err);
reject(err);
});
});
return new Promise((resolve, reject) => {
verifyGenerator
.init(pubKey)
.then(() => {
console.log("[Promise]verifyGenerator init success!");
resolve("init success");
})
.catch((err) => {
console.error("[Promise]verifyGenerator init failed. error is " + err);
reject(err);
});
});
}
async function updateVerify(verifyGenerator, dataBlob) {
return new Promise((resolve, reject) => {
verifyGenerator
.update(dataBlob)
.then(() => {
console.log("[Promise]verifyGenerator update success!");
resolve("update success");
})
.catch((err) => {
console.error(
"[Promise]verifyGenerator update failed. error is " + err
);
reject(err);
});
});
return new Promise((resolve, reject) => {
verifyGenerator
.update(dataBlob)
.then(() => {
console.log("[Promise]verifyGenerator update success!");
resolve("update success");
})
.catch((err) => {
console.error(
"[Promise]verifyGenerator update failed. error is " + err
);
reject(err);
});
});
}
async function verifyForVerify(verifyGenerator, dataBlob, signDataBlob) {
return new Promise((resolve, reject) => {
verifyGenerator
.verify(dataBlob, signDataBlob)
.then((verifyOutput) => {
console.log("[Promise]signGenerator sign success!");
resolve(verifyOutput);
})
.catch((err) => {
console.error("[Promise]signGenerator sign failed. error is " + err);
reject(err);
});
});
return new Promise((resolve, reject) => {
verifyGenerator
.verify(dataBlob, signDataBlob)
.then((verifyOutput) => {
console.log("[Promise]signGenerator sign success!");
resolve(verifyOutput);
})
.catch((err) => {
console.error("[Promise]signGenerator sign failed. error is " + err);
reject(err);
});
});
}
async function generateAsySecret(generator, priKey, pubKey) {
return new Promise((resolve, reject) => {
generator
.generateSecret(priKey, pubKey)
.then((output) => {
console.log("[Promise]generateSecret success!");
resolve(output);
})
.catch((err) => {
console.error("[Promise]generateSecret failed. error is " + err);
reject(err);
});
});
return new Promise((resolve, reject) => {
generator
.generateSecret(priKey, pubKey)
.then((output) => {
console.log("[Promise]generateSecret success!");
resolve(output);
})
.catch((err) => {
console.error("[Promise]generateSecret failed. error is " + err);
reject(err);
});
});
}
async function encryptAndDecryptNormalProcess(asyAlgoName, cipherAlgoName) {
var globalCipherText;
var globalRsaKeyPair;
var globalText = "This is a cipher test";
var input = { data: stringTouInt8Array(globalText) };
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, input);
})
.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("[promise]decrypt doFinal out is null");
} else {
console.log(
"[promise]decrypt doFinal out hex: " +
uInt8ArrayToShowStr(finalOutput.data)
);
}
let decryptData = uInt8ArrayToString(finalOutput.data);
expect(decryptData == globalText).assertTrue();
resolve();
})
.catch((err) => {
console.error(
"[promise] encryptAndDecryptNormalProcess catch err:" + err
);
reject(err);
});
});
var globalCipherText;
var globalRsaKeyPair;
var globalText = "This is a cipher test";
var input = { data: stringTouInt8Array(globalText) };
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, input);
})
.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("[promise]decrypt doFinal out is null");
} else {
console.log(
"[promise]decrypt doFinal out hex: " +
uInt8ArrayToShowStr(finalOutput.data)
);
}
let decryptData = uInt8ArrayToString(finalOutput.data);
expect(decryptData == globalText).assertTrue();
resolve();
})
.catch((err) => {
console.error(
"[promise] encryptAndDecryptNormalProcess catch err:" + err
);
reject(err);
});
});
}
async function signAndVerifyNormalProcess(asyAlgoName, signVerifyAlgoName) {
var globalRsaKeyPair;
var globalSignBlob;
var globalText = "This is a sign test";
var input = { data: stringTouInt8Array(globalText) };
return new Promise((resolve, reject) => {
var rsaGenerator = createAsyKeyGenerator(asyAlgoName);
expect(rsaGenerator != null).assertTrue();
var signGenerator = createAsySign(signVerifyAlgoName);
expect(signGenerator != null).assertTrue();
var verifyGenerator = createAsyVerify(signVerifyAlgoName);
expect(verifyGenerator != null).assertTrue();
generateAsyKeyPair(rsaGenerator)
.then((rsaKeyPair) => {
expect(rsaKeyPair != null).assertTrue();
globalRsaKeyPair = rsaKeyPair;
return initSign(signGenerator, globalRsaKeyPair.priKey);
})
.then((initData) => {
expect(initData === "init success").assertTrue();
return updateSign(signGenerator, input);
})
.then((updateData) => {
expect(updateData === "update success").assertTrue();
return signForSign(signGenerator, input);
})
.then((finalOutput) => {
expect(finalOutput != null).assertTrue();
globalSignBlob = finalOutput;
console.log("signOutput: " + uInt8ArrayToShowStr(globalSignBlob.data));
return initVerify(verifyGenerator, globalRsaKeyPair.pubKey);
})
.then((initData) => {
expect(initData === "init success").assertTrue();
return updateVerify(verifyGenerator, input);
})
.then((updateData) => {
expect(updateData === "update success").assertTrue();
return verifyForVerify(verifyGenerator, input, globalSignBlob);
})
.then((finalStatus) => {
expect(finalStatus).assertTrue();
resolve();
})
.catch((err) => {
console.error("[promise] signAndVerifyNormalProcess catch err:" + err);
reject(err);
});
});
var globalRsaKeyPair;
var globalSignBlob;
var globalText = "This is a sign test";
var input = { data: stringTouInt8Array(globalText) };
return new Promise((resolve, reject) => {
var rsaGenerator = createAsyKeyGenerator(asyAlgoName);
expect(rsaGenerator != null).assertTrue();
var signGenerator = createAsySign(signVerifyAlgoName);
expect(signGenerator != null).assertTrue();
var verifyGenerator = createAsyVerify(signVerifyAlgoName);
expect(verifyGenerator != null).assertTrue();
generateAsyKeyPair(rsaGenerator)
.then((rsaKeyPair) => {
expect(rsaKeyPair != null).assertTrue();
globalRsaKeyPair = rsaKeyPair;
return initSign(signGenerator, globalRsaKeyPair.priKey);
})
.then((initData) => {
expect(initData === "init success").assertTrue();
return updateSign(signGenerator, input);
})
.then((updateData) => {
expect(updateData === "update success").assertTrue();
return signForSign(signGenerator, input);
})
.then((finalOutput) => {
expect(finalOutput != null).assertTrue();
globalSignBlob = finalOutput;
console.log("signOutput: " + uInt8ArrayToShowStr(globalSignBlob.data));
return initVerify(verifyGenerator, globalRsaKeyPair.pubKey);
})
.then((initData) => {
expect(initData === "init success").assertTrue();
return updateVerify(verifyGenerator, input);
})
.then((updateData) => {
expect(updateData === "update success").assertTrue();
return verifyForVerify(verifyGenerator, input, globalSignBlob);
})
.then((finalStatus) => {
expect(finalStatus).assertTrue();
resolve();
})
.catch((err) => {
console.error("[promise] signAndVerifyNormalProcess catch err:" + err);
reject(err);
});
});
}
async function signAndVerifyNormalProcessDataException(asyAlgoName, signVerifyAlgoName, dataType) {
var globalRsaKeyPair;
var globalSignBlob;
var globalText = "This is a sign test";
var input;
if (dataType == "null") {
input = null;
} else {
input = { data: stringTouInt8Array(globalText) };
};
return new Promise((resolve, reject) => {
var rsaGenerator = createAsyKeyGenerator(asyAlgoName);
expect(rsaGenerator != null).assertTrue();
var signGenerator = createAsySign(signVerifyAlgoName);
expect(signGenerator != null).assertTrue();
var verifyGenerator = createAsyVerify(signVerifyAlgoName);
expect(verifyGenerator != null).assertTrue();
generateAsyKeyPair(rsaGenerator)
.then((rsaKeyPair) => {
expect(rsaKeyPair != null).assertTrue();
globalRsaKeyPair = rsaKeyPair;
return initSign(signGenerator, globalRsaKeyPair.priKey);
})
.then((initData) => {
expect(initData === "init success").assertTrue();
return updateSign(signGenerator, input);
})
.then((updateData) => {
expect(updateData === "update success").assertTrue();
return signForSign(signGenerator, input);
})
.then((finalOutput) => {
expect(finalOutput != null).assertTrue();
globalSignBlob = finalOutput;
console.log("signOutput: " + uInt8ArrayToShowStr(globalSignBlob.data));
return initVerify(verifyGenerator, globalRsaKeyPair.pubKey);
})
.then((initData) => {
expect(initData === "init success").assertTrue();
return updateVerify(verifyGenerator, input);
})
.then((updateData) => {
expect(updateData === "update success").assertTrue();
return verifyForVerify(verifyGenerator, input, globalSignBlob);
})
.then((finalStatus) => {
expect(finalStatus).assertTrue();
if (dataType == "null") {
reject();
} else {
resolve();
}
})
.catch((err) => {
console.error("[promise] signAndVerifyNormalProcess catch err:" + err);
if (dataType =="null") {
resolve(err);
} else {
reject(err);
}
});
});
var globalRsaKeyPair;
var globalSignBlob;
var globalText = "This is a sign test";
var input;
if (dataType == "null") {
input = null;
} else {
input = { data: stringTouInt8Array(globalText) };
}
;
return new Promise((resolve, reject) => {
var rsaGenerator = createAsyKeyGenerator(asyAlgoName);
var signGenerator = createAsySign(signVerifyAlgoName);
var verifyGenerator = createAsyVerify(signVerifyAlgoName);
generateAsyKeyPair(rsaGenerator)
.then((rsaKeyPair) => {
globalRsaKeyPair = rsaKeyPair;
return initSign(signGenerator, globalRsaKeyPair.priKey);
})
.then((initData) => {
return updateSign(signGenerator, input);
})
.then((updateData) => {
return signForSign(signGenerator, input);
})
.then((finalOutput) => {
globalSignBlob = finalOutput;
console.log("signOutput: " + uInt8ArrayToShowStr(globalSignBlob.data));
return initVerify(verifyGenerator, globalRsaKeyPair.pubKey);
})
.then((initData) => {
return updateVerify(verifyGenerator, input);
})
.then((updateData) => {
return verifyForVerify(verifyGenerator, input, globalSignBlob);
})
.then((finalStatus) => {
if (dataType == "null") {
reject();
} else {
resolve();
}
})
.catch((err) => {
console.error("[promise] signAndVerifyNormalProcess catch err code:" + err.code);
if (dataType == "null") {
resolve(err.code);
} else {
reject(err);
}
});
});
}
async function convertKeyEncryptAndDecryptProcess(asyAlgoName) {
return new Promise((resolve, reject) => {
var rsaGenerator = createAsyKeyGenerator(asyAlgoName);
expect(rsaGenerator != null).assertTrue();
generateAsyKeyPair(rsaGenerator)
.then((rsaKeyPair) => {
expect(rsaKeyPair != null).assertTrue();
let encodedPubKey = rsaKeyPair.pubKey.getEncoded();
let encodedPriKey = rsaKeyPair.priKey.getEncoded();
return convertAsyKey(rsaGenerator, encodedPubKey, encodedPriKey);
})
.then((convertKeyPair) => {
expect(convertKeyPair != null).assertTrue();
let encodedConvertPubKey = convertKeyPair.pubKey.getEncoded();
console.warn(
"[Promise]: pubKey.getAlgorithm= " + convertKeyPair.pubKey.algName
);
console.warn(
"[Promise]: pubKey.getEncoded= " + encodedConvertPubKey.data
);
console.warn(
"[Promise]: pubKey.getFormat= " + convertKeyPair.pubKey.format
);
let encodedConvertPriKey = convertKeyPair.priKey.getEncoded();
console.warn(
"[Promise]: priKey.getAlgorithm= " + convertKeyPair.priKey.algName
);
console.warn(
"[Promise]: priKey.getEncoded= " + encodedConvertPriKey.data
);
console.warn(
"[Promise]: priKey.getFormat= " + convertKeyPair.priKey.format
);
resolve();
})
.catch((err) => {
console.error(
"[promise] convertKeyEncryptAndDecryptProcess catch err:" + err
);
reject(err);
});
});
return new Promise((resolve, reject) => {
var rsaGenerator = createAsyKeyGenerator(asyAlgoName);
expect(rsaGenerator != null).assertTrue();
generateAsyKeyPair(rsaGenerator)
.then((rsaKeyPair) => {
expect(rsaKeyPair != null).assertTrue();
let encodedPubKey = rsaKeyPair.pubKey.getEncoded();
let encodedPriKey = rsaKeyPair.priKey.getEncoded();
return convertAsyKey(rsaGenerator, encodedPubKey, encodedPriKey);
})
.then((convertKeyPair) => {
expect(convertKeyPair != null).assertTrue();
let encodedConvertPubKey = convertKeyPair.pubKey.getEncoded();
console.warn(
"[Promise]: pubKey.getAlgorithm= " + convertKeyPair.pubKey.algName
);
console.warn(
"[Promise]: pubKey.getEncoded= " + encodedConvertPubKey.data
);
console.warn(
"[Promise]: pubKey.getFormat= " + convertKeyPair.pubKey.format
);
let encodedConvertPriKey = convertKeyPair.priKey.getEncoded();
console.warn(
"[Promise]: priKey.getAlgorithm= " + convertKeyPair.priKey.algName
);
console.warn(
"[Promise]: priKey.getEncoded= " + encodedConvertPriKey.data
);
console.warn(
"[Promise]: priKey.getFormat= " + convertKeyPair.priKey.format
);
resolve();
})
.catch((err) => {
console.error(
"[promise] convertKeyEncryptAndDecryptProcess catch err:" + err
);
reject(err);
});
});
}
async function keyAgreementProcess(ECDHAlgoName) {
var globalRsaKeyPair;
return new Promise((resolve, reject) => {
var rsaGenerator = createAsyKeyGenerator(ECDHAlgoName);
expect(rsaGenerator != null).assertTrue();
var globalECDHData = createAsyKeyAgreement(ECDHAlgoName);
expect(globalECDHData != null).assertTrue();
generateAsyKeyPair(rsaGenerator)
.then((rsaKeyPair) => {
expect(rsaKeyPair != null).assertTrue();
globalRsaKeyPair = rsaKeyPair;
return generateAsySecret(globalECDHData, globalRsaKeyPair.priKey, globalRsaKeyPair.pubKey);
})
.then((result) => {
console.warn("result data is " + uInt8ArrayToShowStr(result.data));
expect(result != null).assertTrue();
resolve();
})
.catch((err) => {
console.error("[promise] keyAgreementProcess catch err:" + err);
reject(err);
});
});
var globalRsaKeyPair;
return new Promise((resolve, reject) => {
var rsaGenerator = createAsyKeyGenerator(ECDHAlgoName);
expect(rsaGenerator != null).assertTrue();
var globalECDHData = createAsyKeyAgreement(ECDHAlgoName);
expect(globalECDHData != null).assertTrue();
generateAsyKeyPair(rsaGenerator)
.then((rsaKeyPair) => {
expect(rsaKeyPair != null).assertTrue();
globalRsaKeyPair = rsaKeyPair;
return generateAsySecret(globalECDHData, globalRsaKeyPair.priKey, globalRsaKeyPair.pubKey);
})
.then((result) => {
console.warn("result data is " + uInt8ArrayToShowStr(result.data));
expect(result != null).assertTrue();
resolve();
})
.catch((err) => {
console.error("[promise] keyAgreementProcess catch err:" + err);
reject(err);
});
});
}
async function AsyPriKeyClearProcess(asyAlgoName) {
return new Promise((resolve, reject) => {
var rsaGenerator = createAsyKeyGenerator(asyAlgoName);
expect(rsaGenerator != null).assertTrue();
generateAsyKeyPair(rsaGenerator)
.then((rsaKeyPair) => {
expect(rsaKeyPair != null).assertTrue();
let result = rsaKeyPair.priKey.clearMem();
console.log("result is: " + result);
expect(result == undefined).assertTrue();
resolve();
})
.catch((err) => {
console.error("[promise] AsyPriKeyClearProcess catch err:" + err);
reject(err);
});
});
}
async function createAsyKeyGeneratorFail(asyAlgoName) {
return new Promise((resolve, reject) => {
var rsaGenerator = createAsyKeyGenerator(asyAlgoName);
resolve(rsaGenerator);
expect(rsaGenerator == "TypeError: Cannot read property algName of null").assertTrue();
if (rsaGenerator != "TypeError: Cannot read property algName of null") {
reject();
}
});
return new Promise((resolve, reject) => {
var rsaGenerator = createAsyKeyGenerator(asyAlgoName);
expect(rsaGenerator != null).assertTrue();
generateAsyKeyPair(rsaGenerator)
.then((rsaKeyPair) => {
expect(rsaKeyPair != null).assertTrue();
let result = rsaKeyPair.priKey.clearMem();
console.log("result is: " + result);
expect(result == undefined).assertTrue();
resolve();
})
.catch((err) => {
console.error("[promise] AsyPriKeyClearProcess catch err:" + err);
reject(err);
});
});
}
async function createAsySignFail(
asyAlgoName,
signVerifyAlgoName,
signVerifyAlgoName1,
signVerifyAlgoName2,
signVerifyAlgoName3
) {
return new Promise((resolve, reject) => {
var rsaGenerator = createAsyKeyGenerator(asyAlgoName);
expect(rsaGenerator != null).assertTrue();
var rsaKeyPair = generateAsyKeyPair(rsaGenerator);
expect(rsaKeyPair != null).assertTrue();
var signGenerator = createAsySign(signVerifyAlgoName);
expect(signGenerator == "TypeError: Cannot read property algName of undefined").assertTrue();
var signGenerator = createAsySign(signVerifyAlgoName1);
expect(signGenerator == "TypeError: Cannot read property algName of undefined").assertTrue();
var signGenerator = createAsySign(signVerifyAlgoName2);
expect(signGenerator == "TypeError: Cannot read property algName of undefined").assertTrue();
var signGenerator = createAsySign(signVerifyAlgoName3);
resolve(signGenerator);
expect(signGenerator == "TypeError: Cannot read property algName of undefined").assertTrue();
if (signGenerator != "TypeError: Cannot read property algName of undefined") {
reject();
}
});
}
async function createAsyVerifyFail(
asyAlgoName,
signVerifyAlgoName,
signVerifyAlgoName1,
signVerifyAlgoName2,
signVerifyAlgoName3
) {
return new Promise((resolve, reject) => {
var rsaGenerator = createAsyKeyGenerator(asyAlgoName);
expect(rsaGenerator != null).assertTrue();
var rsaKeyPair = generateAsyKeyPair(rsaGenerator);
expect(rsaKeyPair != null).assertTrue();
var verifyGenerator = createAsyVerify(signVerifyAlgoName);
expect(verifyGenerator == "TypeError: Cannot read property algName of undefined").assertTrue();
var verifyGenerator = createAsyVerify(signVerifyAlgoName1);
expect(verifyGenerator == "TypeError: Cannot read property algName of undefined").assertTrue();
var verifyGenerator = createAsyVerify(signVerifyAlgoName2);
expect(verifyGenerator == "TypeError: Cannot read property algName of undefined").assertTrue();
var verifyGenerator = createAsyVerify(signVerifyAlgoName3);
resolve(verifyGenerator);
expect(verifyGenerator == "TypeError: Cannot read property algName of undefined").assertTrue();
if (verifyGenerator != "TypeError: Cannot read property algName of undefined") {
reject();
}
});
}
export {
encryptAndDecryptNormalProcess,
signAndVerifyNormalProcess,
convertKeyEncryptAndDecryptProcess,
keyAgreementProcess,
AsyPriKeyClearProcess,
signAndVerifyNormalProcessDataException,
createAsyKeyGeneratorFail,
createAsySignFail,
createAsyVerifyFail,
encryptAndDecryptNormalProcess,
signAndVerifyNormalProcess,
convertKeyEncryptAndDecryptProcess,
keyAgreementProcess,
AsyPriKeyClearProcess,
signAndVerifyNormalProcessDataException
};
......@@ -14,291 +14,256 @@
*/
import { expect } from "@ohos/hypium";
import cryptoFramework from "@ohos.security.cryptoFramework";
import {
stringTouInt8Array,
uInt8ArrayToShowStr,
uInt8ArrayToString,
} from "../common/publicDoString";
import { stringTouInt8Array, uInt8ArrayToShowStr, uInt8ArrayToString, } from "../common/publicDoString";
async function generateSymKey(symKeyGenerator) {
return new Promise((resolve, reject) => {
symKeyGenerator.generateSymKey((err, symKey) => {
if (err) {
console.error("[Callback]generateSymKey failed. error is " + err);
reject(err);
} else {
console.log("[Callback]generateSymKey success. symKey is " + symKey);
console.warn("[Callback]key algName:" + symKey.algName);
console.warn("[Callback]key format:" + symKey.format);
var encodeKey = symKey.getEncoded();
console.warn(
"[Callback]key getEncoded hex: " + uInt8ArrayToShowStr(encodeKey.data)
);
resolve(symKey);
}
return new Promise((resolve, reject) => {
symKeyGenerator.generateSymKey((err, symKey) => {
if (err) {
console.error("[Callback]generateSymKey failed. error is " + err);
reject(err);
} else {
console.log("[Callback]generateSymKey success. symKey is " + symKey);
console.warn("[Callback]key algName:" + symKey.algName);
console.warn("[Callback]key format:" + symKey.format);
var encodeKey = symKey.getEncoded();
console.warn(
"[Callback]key getEncoded hex: " + uInt8ArrayToShowStr(encodeKey.data)
);
resolve(symKey);
}
});
});
});
}
async function initMac(macGenerator, symKey) {
return new Promise((resolve, reject) => {
macGenerator.init(symKey, (err) => {
if (err) {
console.error("[Callback]macGenerator init failed. error is " + err);
reject(err);
} else {
console.log("[Callback]macGenerator init success!");
resolve("init success");
}
return new Promise((resolve, reject) => {
macGenerator.init(symKey, (err) => {
if (err) {
console.error("[Callback]macGenerator init failed. error is " + err);
reject(err);
} else {
console.log("[Callback]macGenerator init success!");
resolve("init success");
}
});
});
});
}
async function updateMac(macGenerator, dataBlob) {
return new Promise((resolve, reject) => {
macGenerator.update(dataBlob, (err) => {
if (err) {
console.error("[Callback]macGenerator update failed. error is " + err);
reject(err);
} else {
console.log("[Callback]macGenerator update success!");
resolve("update success");
}
return new Promise((resolve, reject) => {
macGenerator.update(dataBlob, (err) => {
if (err) {
console.error("[Callback]macGenerator update failed. error is " + err);
reject(err);
} else {
console.log("[Callback]macGenerator update success!");
resolve("update success");
}
});
});
});
}
async function doFinalMac(macGenerator) {
return new Promise((resolve, reject) => {
macGenerator.doFinal((err, output) => {
if (err) {
console.error("[Callback]macGenerator doFinal failed. error is " + err);
reject(err);
} else {
console.log(
"[Callback]macGenerator doFinal success! output is: " + output
);
resolve(output);
}
return new Promise((resolve, reject) => {
macGenerator.doFinal((err, output) => {
if (err) {
console.error("[Callback]macGenerator doFinal failed. error is " + err);
reject(err);
} else {
console.log(
"[Callback]macGenerator doFinal success! output is: " + output
);
resolve(output);
}
});
});
});
}
async function updateMd(mdGenerator, dataBlob) {
return new Promise((resolve, reject) => {
mdGenerator.update(dataBlob, (err) => {
if (err) {
console.error("[Callback]mdGenerator update failed. error is " + err);
reject(err);
} else {
console.log("[Callback]mdGenerator update success!");
resolve("update success");
}
return new Promise((resolve, reject) => {
mdGenerator.update(dataBlob, (err) => {
if (err) {
console.error("[Callback]mdGenerator update failed. error is " + err);
reject(err);
} else {
console.log("[Callback]mdGenerator update success!");
resolve("update success");
}
});
});
});
}
async function digestMd(mdGenerator) {
return new Promise((resolve, reject) => {
mdGenerator.digest((err, output) => {
if (err) {
console.error("[Callback]mdGenerator digest failed. error is " + err);
reject(err);
} else {
console.log(
"[Callback]mdGenerator digest success! output is: " + output
);
resolve(output);
}
return new Promise((resolve, reject) => {
mdGenerator.digest((err, output) => {
if (err) {
console.error("[Callback]mdGenerator digest failed. error is " + err);
reject(err);
} else {
console.log(
"[Callback]mdGenerator digest success! output is: " + output
);
resolve(output);
}
});
});
});
}
async function testMDDigestCallback(MDAlgoName) {
var globalMd;
var globalText = "my test data";
var inBlob = {
data: stringTouInt8Array(globalText),
};
var globalMd;
var globalText = "my test data";
var inBlob = {
data: stringTouInt8Array(globalText),
};
return new Promise((resolve, reject) => {
globalMd = cryptoFramework.createMd(MDAlgoName);
expect(globalMd != null).assertTrue();
console.warn("md= " + globalMd);
console.warn("MD algName is: " + globalMd.algName);
return new Promise((resolve, reject) => {
globalMd = cryptoFramework.createMd(MDAlgoName);
expect(globalMd != null).assertTrue();
console.warn("md= " + globalMd);
console.warn("MD algName is: " + globalMd.algName);
updateMd(globalMd, inBlob)
.then((updateData) => {
expect(updateData === "update success").assertTrue();
return digestMd(globalMd);
})
.then((digestBlob) => {
console.warn(
"[callback]: digest result: " + uInt8ArrayToShowStr(digestBlob.data)
);
let mdLen = globalMd.getMdLength();
console.warn("Md len: " + mdLen);
expect(digestBlob != null && mdLen != 0 && mdLen != null).assertTrue();
resolve();
})
.catch((err) => {
console.error("testMDDigestCallback catch error: " + err);
reject(err);
});
});
updateMd(globalMd, inBlob)
.then((updateData) => {
expect(updateData === "update success").assertTrue();
return digestMd(globalMd);
})
.then((digestBlob) => {
console.warn(
"[callback]: digest result: " + uInt8ArrayToShowStr(digestBlob.data)
);
let mdLen = globalMd.getMdLength();
console.warn("Md len: " + mdLen);
expect(digestBlob != null && mdLen != 0 && mdLen != null).assertTrue();
resolve();
})
.catch((err) => {
console.error("testMDDigestCallback catch error: " + err);
reject(err);
});
});
}
async function testMDDigestCallbackLen(MDAlgoName, DatablobLen) {
var globalMd;
var i;
var globalText;
var t = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefhijklmnopqrstuvwxyz",n = t.length,s="";
for (i = 0; i < DatablobLen; i++){
globalText += t.charAt(Math.floor(Math.random() * n));
}
console.warn("Datablob = " + globalText);
var ginBlob = {
data: stringTouInt8Array(globalText),
};
return new Promise((resolve, reject) => {
globalMd = cryptoFramework.createMd(MDAlgoName);
expect(globalMd != null).assertTrue();
console.warn("md= " + globalMd);
console.warn("MD algName is: " + globalMd.algName);
updateMd(globalMd, ginBlob)
.then((updateData) => {
expect(updateData === "update success").assertTrue();
return digestMd(globalMd);
})
.then((digestBlob) => {
console.warn(
"[callback]: digest result: " + uInt8ArrayToShowStr(digestBlob.data)
);
let mdLen = globalMd.getMdLength();
console.warn("Md len: " + mdLen);
expect(digestBlob != null && mdLen != 0 && mdLen != null).assertTrue();
resolve();
})
.catch((err) => {
console.error("testMDDigestCallback catch error: " + err);
reject(err);
});
});
}
async function testMDDigestCallbackLenNull(MDAlgoName) {
var globalMd;
var globalText1 = null;
var globalText2 = 0;
var inBlob = {
data: stringTouInt8Array(globalText2),
};
return new Promise((resolve, reject) => {
globalMd = cryptoFramework.createMd(MDAlgoName);
expect(globalMd != null).assertTrue();
console.warn("md= " + globalMd);
console.warn("MD algName is: " + globalMd.algName);
var globalMd;
var i;
var globalText;
var t = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefhijklmnopqrstuvwxyz", n = t.length, s = "";
for (i = 0; i < DatablobLen; i++) {
globalText += t.charAt(Math.floor(Math.random() * n));
}
console.warn("Datablob = " + globalText);
var ginBlob = {
data: stringTouInt8Array(globalText),
};
updateMd(globalMd, globalText1)
.then((updateData) => {
console.warn("updateData: " + updateData);
})
.catch((err) => {
console.error("testMDDigestCallback catch error1: " + err);
expect(err == "Error: inBlob is null").assertTrue();
});
return new Promise((resolve, reject) => {
globalMd = cryptoFramework.createMd(MDAlgoName);
expect(globalMd != null).assertTrue();
console.warn("md= " + globalMd);
console.warn("MD algName is: " + globalMd.algName);
updateMd(globalMd, inBlob)
.then((updateData) => {
console.warn("updateData: " + updateData);
reject();
})
.catch((err) => {
console.error("testMDDigestCallback catch error2: " + err);
expect(err == "Error: inBlob is null").assertTrue();
resolve();
});
});
updateMd(globalMd, ginBlob)
.then((updateData) => {
expect(updateData === "update success").assertTrue();
return digestMd(globalMd);
})
.then((digestBlob) => {
console.warn(
"[callback]: digest result: " + uInt8ArrayToShowStr(digestBlob.data)
);
let mdLen = globalMd.getMdLength();
console.warn("Md len: " + mdLen);
expect(digestBlob != null && mdLen != 0 && mdLen != null).assertTrue();
resolve();
})
.catch((err) => {
console.error("testMDDigestCallback catch error: " + err);
reject(err);
});
});
}
async function testMDErrorAlgorithm(MDAlgoName) {
var globalMd;
var globalMd;
return new Promise((resolve, reject) => {
console.warn("md= test begin");
try {
globalMd = cryptoFramework.createMd(MDAlgoName);
reject();
} catch (error) {
console.error("[Promise]: error code: " + error.code + ", message is: " + error.message);
expect(error.code == 801).assertTrue();
resolve();
}
});
return new Promise((resolve, reject) => {
console.warn("md= test begin");
try {
globalMd = cryptoFramework.createMd(MDAlgoName);
reject();
} catch (error) {
console.error("[Promise]: error code: " + error.code + ", message is: " + error.message);
expect(error.code == 801).assertTrue();
resolve();
}
});
}
async function testMDErrorAlgorithmNull(MDAlgoName) {
var globalMd;
var globalMd;
return new Promise((resolve, reject) => {
try {
globalMd = cryptoFramework.createMd(MDAlgoName);
reject();
} catch (error) {
console.error("[Promise]: error code: " + error.code + ", message is: " + error.message);
expect(error.code == 401).assertTrue();
resolve();
}
});
return new Promise((resolve, reject) => {
try {
globalMd = cryptoFramework.createMd(MDAlgoName);
reject();
} catch (error) {
console.error("[Promise]: error code: " + error.code + ", message is: " + error.message);
expect(error.code == 401).assertTrue();
resolve();
}
});
}
async function testHMACDigestCallback(HMACAlgoName, keyAlgoName) {
var globalHMAC;
var globalText = "my test data";
var globalsymKeyGenerator;
var ginBlob = {
data: stringTouInt8Array(globalText),
};
var globalHMAC;
var globalText = "my test data";
var globalsymKeyGenerator;
var ginBlob = {
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);
expect(globalsymKeyGenerator != null).assertTrue();
console.warn("symKeyGenerator algName:" + globalsymKeyGenerator.algName);
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);
expect(globalsymKeyGenerator != null).assertTrue();
console.warn("symKeyGenerator algName:" + globalsymKeyGenerator.algName);
generateSymKey(globalsymKeyGenerator)
.then((symKey) => {
expect(symKey != null).assertTrue();
return initMac(globalHMAC, symKey);
})
.then((initData) => {
expect(initData === "init success").assertTrue();
return updateMac(globalHMAC, ginBlob);
})
.then((updateData) => {
expect(updateData === "update success").assertTrue();
return doFinalMac(globalHMAC);
})
.then((macOutput) => {
console.warn("HMAC result:" + macOutput.data);
let macLen = globalHMAC.getMacLength();
console.warn("MAC len:" + macLen);
expect(macOutput != null && macLen != 0 && macLen != null).assertTrue();
resolve();
})
.catch((err) => {
console.error("testHMACDigestCallback catch error: " + err);
reject(err);
});
});
generateSymKey(globalsymKeyGenerator)
.then((symKey) => {
expect(symKey != null).assertTrue();
return initMac(globalHMAC, symKey);
})
.then((initData) => {
expect(initData === "init success").assertTrue();
return updateMac(globalHMAC, ginBlob);
})
.then((updateData) => {
expect(updateData === "update success").assertTrue();
return doFinalMac(globalHMAC);
})
.then((macOutput) => {
console.warn("HMAC result:" + macOutput.data);
let macLen = globalHMAC.getMacLength();
console.warn("MAC len:" + macLen);
expect(macOutput != null && macLen != 0 && macLen != null).assertTrue();
resolve();
})
.catch((err) => {
console.error("testHMACDigestCallback catch error: " + err);
reject(err);
});
});
}
export { testMDDigestCallback, testHMACDigestCallback, testMDErrorAlgorithm,
testMDErrorAlgorithmNull, testMDDigestCallbackLen, testMDDigestCallbackLenNull };
export {
testMDDigestCallback,
testHMACDigestCallback,
testMDErrorAlgorithm,
testMDErrorAlgorithmNull,
testMDDigestCallbackLen
};
......@@ -58,67 +58,6 @@ async function testSecurityRandomCallback(length) {
});
}
async function testSecurityRandomLengthCallback(length) {
var rand;
return new Promise((resolve, reject) => {
rand = cryptoFramework.createRandom();
expect(rand != null).assertTrue();
if (length != null) {
rand.generateRandom(length, (err, randData) => {
if (err) {
console.error(
"[callback]generateRandom catch error:" +
err +
"[callback]: error code: " +
err.code
);
expect(err.code == 401).assertTrue();
resolve();
} else {
expect(randData != null).assertTrue();
reject();
}
});
} else {
try {
rand.generateRandom(length);
reject();
} catch (error) {
console.error(
"[callback]generateRandom catch err1:" +
error +
"[callback]: error code: " +
error.code
);
resolve();
}
}
});
}
async function testSecurityRandomCallbackSeed(data) {
var rand;
return new Promise((resolve, reject) => {
rand = cryptoFramework.createRandom();
expect(rand != null).assertTrue();
try {
rand.setSeed(data);
reject();
} catch (error) {
console.error(
"[callback]setSeed catch err:" +
error +
"[callback]: error code: " +
error.code
);
expect(error.code == 401).assertTrue();
resolve();
}
});
}
export {
testSecurityRandomCallback,
testSecurityRandomLengthCallback,
testSecurityRandomCallbackSeed,
};
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册