Flutter OHOS flutter_keychain(字符串安全存储)
flutter_keychain
一个支持通过 Keychain 和 Keystore 支持字符串安全存储的 Flutter 插件
如果您有其他类型想要存储,则需要序列化为 UTF-8 字符串。
使用
复制代码
鸿蒙 OS 代码
RSA 密钥封装
async encrypt(input: string): Promise<string{ const options: huks.HuksOptions = { properties: this.getAesEncryptProperties(), inData: StringToUint8Array(input) } try { let huksSessionHandle: huks.HuksSessionHandle = await huks.initSession(this.keyAlias, options) let handle: number = huksSessionHandle.handle let huksReturnResult: huks.HuksReturnResult = await huks.finishSession(handle, options) let cipherData: Uint8Array = huksReturnResult.outData as Uint8Array return Uint8ArrayToString(cipherData) } catch (err) { Log.e(TAG, "Failed to encrypt, err =" + JSON.stringify(err)) } return '' } async decrypt(input: string): Promise<string{ const options: huks.HuksOptions = { properties: this.getAesDecryptProperties(), inData: StringToUint8Array(input) } try { let huksSessionHandle: huks.HuksSessionHandle = await huks.initSession(this.keyAlias, options) let handle: number = huksSessionHandle.handle let huksReturnResult: huks.HuksReturnResult = await huks.finishSession(handle, options) let cipherData: Uint8Array = huksReturnResult.outData as Uint8Array return Uint8ArrayToString(cipherData) } catch (err) { Log.e(TAG, "Failed to decrypt, err =" + JSON.stringify(err)) } return '' }
存储
复制代码
获取
复制代码
移除
复制代码
清空
复制代码
刷新
复制代码
评论