Home > Web Front-end > JS Tutorial > body text

How to operate vue.js to use 3DES encryption

php中世界最好的语言
Release: 2018-05-28 15:34:54
Original
2633 people have browsed it

This time I will show you how to use 3DES encryption to operate vue.js, and what are the precautions to use 3DES encryption when operating vue.js. The following is a practical case, let's take a look.

How to use 3des encryption in a project created by VUE-CLI scaffolding:

npm install crypto-js --save-dev
Copy after login
import CryptoJS from 'crypto-js'
Copy after login
//DES加密 Pkcs7填充方式
encryptByDES(message, key){
  const keyHex = CryptoJS.enc.Utf8.parse(key);
  const encrypted = CryptoJS.DES.encrypt(message, keyHex, {
   mode: CryptoJS.mode.ECB,
   padding: CryptoJS.pad.Pkcs7
   });
  return encrypted.toString();
}
//DES解密
decryptByDES(ciphertext, key){
  const keyHex = CryptoJS.enc.Utf8.parse(key);
  // direct decrypt ciphertext
  const decrypted = CryptoJS.DES.decrypt({
     ciphertext: CryptoJS.enc.Base64.parse(ciphertext)
   }, keyHex, {
     mode: CryptoJS.mode.ECB,
     padding: CryptoJS.pad.Pkcs7
  });
  return decrypted.toString(CryptoJS.enc.Utf8);
}
const _key = 'abcdefghijklmn'
const _password = '123456'
//加密
console.log(this.encryptByDES(_password,_key))
//解密
console.log(this.decryptByDES(_password,_key))
Copy after login
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the PHP Chinese website !

Recommended reading:

Detailed explanation of the steps for getting started with vuex

Detailed explanation of the optimization steps using vue-admin-template

The above is the detailed content of How to operate vue.js to use 3DES encryption. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template