HarmonyOS 有没有sha1加密库可以用?

1、 应用数据需要用到SHA1 加密。

2、有没有相应的库可以用,怎么使用呢?

阅读 633
1 个回答

可以使用三方库crypto-js,支持sha1等多种加密方式,参考链接:

https://ohpm.openharmony.cn/\#/cn/detail/@ohos%2Fcrypto-js

参考demo:

import prompt from '@system.prompt';
import CryptoJS from '@ohos/crypto-js'
import  router from "@ohos.router"
@Entry
@Component
struct Sha1Page {
  @State message: string = 'Hello World';

  build() {
    RelativeContainer() {
      Text(this.message)
        .id('Sha1PageHelloWorld')
        .fontSize(50)
        .fontWeight(FontWeight.Bold)
        .alignRules({
          center: { anchor: '__container__', align: VerticalAlign.Center },
          middle: { anchor: '__container__', align: HorizontalAlign.Center }
        })
      Text('sha1')
        .fontSize(20)
        .margin(20)
        .fontWeight(FontWeight.Bold)
        .onClick(() => {
          let hash: string = CryptoJS.SHA1("123456").toString()
          prompt.showToast({ message: 'sha1=' + hash })
          console.log('sha1=' + hash)
        })
    }
    .height('100%')
    .width('100%')
  }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进