4 Star 2 Fork 2

CheungVane/关键资产文档

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
asd 4.46 KB
一键复制 编辑 原始数据 按行查看 历史
CheungVane 提交于 2023-12-01 16:06 +08:00 . update asd.
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)
}
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhang-wenzhi821/critical-asset-documentation.git
git@gitee.com:zhang-wenzhi821/critical-asset-documentation.git
zhang-wenzhi821
critical-asset-documentation
关键资产文档
master

搜索帮助