代码拉取完成,页面将自动刷新
import huks from '@ohos.security.huks';
import promptAction from '@ohos.promptAction';
import hilog from '@ohos.hilog'
let alias = "alias";
async function checkExist(keyAlias) {
let emptyOptions = {
properties:[]
}
await huks.isKeyItemExistV11(keyAlias, emptyOptions).then((data) => {
promptAction.showToast({
message: "别名为: " + keyAlias +"的密钥查询结果是:" + data,
duration: 500,
})
}).catch((err)=>{
promptAction.showToast({
message: "密钥查询失败,错误码是: " + err.code + " 错误码信息: " + err.message,
duration: 6500,
})
})
}
async function checkOldExist(keyAlias) {
let emptyOptions = {
properties:[]
}
await huks.isKeyItemExist(keyAlias, emptyOptions).then((data) => {
promptAction.showToast({
message: "别名为: " + keyAlias +"的密钥查询结果是:" + data,
duration: 500,
})
}).catch((err)=>{
promptAction.showToast({
message: "密钥查询失败,错误码是: " + err.code + " 错误码信息: " + err.message,
duration: 6500,
})
})
}
function GetAesGeneratePropertiesPwdSetProperties() {
var properties = new Array();
var index = 0;
properties[index++] = {
tag: huks.HuksTag.HUKS_TAG_ALGORITHM,
value: huks.HuksKeyAlg.HUKS_ALG_AES
};
properties[index++] = {
tag: huks.HuksTag.HUKS_TAG_KEY_SIZE,
value: huks.HuksKeySize.HUKS_AES_KEY_SIZE_128
};
properties[index++] = {
tag: huks.HuksTag.HUKS_TAG_PURPOSE,
value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT |
huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DECRYPT
}
return properties;
}
async function GenerateKeyPwdSet(keyAlias) {
var options = {
properties: GetAesGeneratePropertiesPwdSetProperties()
}
await huks.generateKeyItem(keyAlias, options).then((data) => {
promptAction.showToast({
message: "成功生成了一个别名为:"+ keyAlias + " 的密钥" ,
duration: 2500,
})
}).catch((err)=>{
promptAction.showToast({
message: "密钥生成失败,错误码是: " + err.code + " 错误吗信息: " + err.message,
duration: 6500,
})
})
}
async function DeleteKey(keyAlias) {
let emptyOptions = {
properties:[]
}
await huks.deleteKeyItem(keyAlias, emptyOptions).then((data) => {
promptAction.showToast({
message: "别名为: "+ keyAlias +" 密钥删除成功!",
duration: 6500,
})
}).catch((err)=>{
promptAction.showToast({
message: "密钥删除失败,错误码是: " + err.code + " 错误吗信息: " + err.message,
duration: 6500,
})
})
}
@Entry
@Component
struct Index {
@State message: string = 'Hello World'
build() {
Column() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
}
.width('100%')
}
Row() {
Button({ type: ButtonType.Normal, stateEffect: true }) {
Text('checkExist')
.fontColor(Color.White)
.fontSize(20)
}
.borderRadius(8)
.width('45%')
.height('5%')
.backgroundColor(0x317bff)
.onClick(() => {
checkExist(alias)
})
.margin(10)
Button({ type: ButtonType.Normal, stateEffect: true }) {
Text('GenerateKeyPwdSet')
.fontColor(Color.White)
.fontSize(20)
}
.borderRadius(8)
.width('45%')
.height('5%')
.backgroundColor(0x317aff)
.onClick(() => {
GenerateKeyPwdSet(alias)
})
.margin(10)
}
Row() {
Button({ type: ButtonType.Normal, stateEffect: true }) {
Text('DeleteKey')
.fontColor(Color.White)
.fontSize(20)
}
.borderRadius(8)
.width('45%')
.height('5%')
.backgroundColor(0x317bff)
.onClick(() => {
DeleteKey(alias)
})
.margin(10)
Button({ type: ButtonType.Normal, stateEffect: true }) {
Text('checkOldExist')
.fontColor(Color.White)
.fontSize(20)
}
.borderRadius(8)
.width('45%')
.height('5%')
.backgroundColor(0x317bff)
.onClick(() => {
checkOldExist(alias)
})
.margin(10)
}
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。