可以使用三方库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%') } }
可以使用三方库crypto-js,支持sha1等多种加密方式,参考链接:
https://ohpm.openharmony.cn/\#/cn/detail/@ohos%2Fcrypto-js
参考demo: