Vuejs uses CryptoJS method examples to achieve encryption and decryption


Install Crypto-JS


VueJs里利用CryptoJs实现加密及解密的方法示例

Step 2 Create
Create a JS file secret

/ ** VueJs里利用CryptoJs实现加密及解密的方法示例 / ** * Encrypt the password entered on the page to verify the background, decrypt the returned data, page display * / let cryptojs = Require (‘crypto-js’); // introduce AES source JSExport default {/ ** Encrypt the password, transfer to the background, verify the background * @Param {string} Word needs encrypted password * @Param {string} KeyStr to password encrypted secrets * @return {string} encrypted ciphertext * * / encrypt (Word) ?, keyStr) {// encryption keyStr = keyStr keyStr: ‘ABGHNJHGSHUYG12’; let key = CryptoJS.enc.Utf8.parse (keyStr); let srcs = CryptoJS.enc.Utf8.parse (word); let encrypted = CryptoJS. AES.Encrypt (SRCS, Key, {Mode: Cryptojs.Mode.ecb, Padding: cryptojs.pad.pkcs7}); Return Encrypted.toString ();}, / ** Decryption on the page after encryption So user to modify * @Param {string} worD Need to encrypt the password * @Param {string} KeyStr to encrypt the secret key * @return {string} Decryption plain text * / decrypt (Word, keyStr) {// Decryption Keystr = Keystr? Keystr: ‘Abghnjhgshuyg12’; Let key = cryptojs.enc.utf8.parse (keyStr); let decrypt = cryptojs.aes.decrypt (Word, Key, {Mode: cryptojs.mode.ecb, padding: cryptojs.pad.pkcs7}); return cryptojs.enc

   


Introducing file VueJs里利用CryptoJs实现加密及解密的方法示例

in the specific plug-in module, encrypting the encrypted password VueJs里利用CryptoJs实现加密及解密的方法示例


encrypt is an encryption function


The first parameter is a clear text

, the second parameter is the secret key used during encryption VueJs里利用CryptoJs实现加密及解密的方法示例

The above is all the content of this article, I hope to help everyone, I hope everyone will support Tumi Clouds.
© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment