电子说
为保证数据安全性,当不需要使用该密钥时,应该删除密钥。
以删除HKDF256密钥为例。
gitee.com/li-shizhen-skin/harmony-os/blob/master/README.md
]/*
* 以下以HKDF256密钥的Promise操作使用为例
*/
import { huks } from '@kit.UniversalKeystoreKit';
/* 1.确定密钥别名 */
let keyAlias = "test_Key";
/* 2.构造空对象 */
let huksOptions: huks.HuksOptions = {
properties: []
}
class throwObject {
isThrow = false;
}
function deleteKeyItem(keyAlias: string, huksOptions: huks.HuksOptions, throwObject: throwObject) {
return new Promise< void >((resolve, reject) = > {
try {
huks.deleteKeyItem(keyAlias, huksOptions, (error, data) = > {
if (error) {
reject(error);
} else {
resolve(data);
}
});
} catch (error) {
throwObject.isThrow = true;
throw (error as Error);
}
});
}
/* 3.删除密钥*/
async function publicDeleteKeyFunc(keyAlias: string, huksOptions: huks.HuksOptions) {
console.info(`enter promise deleteKeyItem`);
let throwObject: throwObject = { isThrow: false };
try {
await deleteKeyItem(keyAlias, huksOptions, throwObject)
.then((data) = > {
console.info(`promise: deleteKeyItem key success, data = ${JSON.stringify(data)}`);
})
.catch((error: Error) = > {
if (throwObject.isThrow) {
throw (error as Error);
} else {
console.error(`promise: deleteKeyItem failed, ${JSON.stringify(error)}`);
}
});
} catch (error) {
console.error(`promise: deleteKeyItem input arg invalid, ${JSON.stringify(error)}`);
}
}
async function testDerive() {
await publicDeleteKeyFunc(keyAlias, huksOptions);
}
审核编辑 黄宇
全部0条评论
快来发表一下你的评论吧 !