HarmonyOS Hongmeng ArkTS performs RSA data encryption

Keywords: HarmonyOS, Hongmeng, ArkTs, JSEncrypt, encryption, third-party library

 

HarmonyOS supports fewer third-party library files due to initial problems. Plug-ins installed using npm install cannot be used normally, resulting in the inability to use more third-party libraries to meet your needs. Of course, we can also use some alternative methods to force the use of these third-party libraries.

 

JSEncrypt_3.3.2 tool class has been submitted to Gitee:luvi/jsencrypt3.3.2

 

start

Copy the downloaded JSEncrypt node_moudules code, read through the author's code, and find out the exported dependency files we need. Open the code and easily find what we need.

d7e1416deaad4906bc260dfaa07f4284.png

 or

964695ea73924b5ab0b93f58434b32c5.png

 

How to use it in the project

Create a new utils directory in the project to store the downloaded third-party library. Import the modules in the library into the code and use them according to the normal usage process.

d405a38975d14ebcbec4f77c9ca247ca.png

const key = "" //公钥
const en = new JSEncrypt()
en.setPublicKey(key)
const ret = en.encrypt("你好")
console.log(ret+" 加密后结果")

 

All roads lead to Rome

 

Guess you like

Origin blog.csdn.net/weixin_44640245/article/details/134536644