current position:Home>Front end login password encryption and decryption

Front end login password encryption and decryption

2022-04-29 08:50:04囍囍囍囍囍囍囍囍囍囍 A

AES encryption

//  Get asymmetric private key 
  handlePublicKey() {
    
     getPublicKey().then((res) => {
    
       this.publicKey = res;
     });
   },
   //  Get symmetric key 
   handleSymmetricKey() {
    
     getSymmetricKey().then((res) => {
    
       this.loginForm.symmetricKey = res;
     });
   },
// RSA encryption 
   encryptRSA(password, pub_key) {
    
     let enc = new JSEncrypt(); //  Declare a new JSEncrypt object 
     enc.setPublicKey(pub_key); //  Configure the public key 
     return enc.encrypt(password); //  encryption 
   },
```// AES encryption 
    encrypt(word, keyStr) {
    
      // keyStr = keyStr ? keyStr : "absoietlj32fai12";
      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();
   	},
    //  Decrypt 
    decrypt(word, keyStr) {
    
      keyStr = keyStr ? keyStr : "absoietlj32fai12";
      var key = CryptoJS.enc.Utf8.parse(keyStr);
      var decrypt = CryptoJS.AES.decrypt(word, key, {
    
        mode: CryptoJS.mode.ECB,
        padding: CryptoJS.pad.Pkcs7,
      });
      return CryptoJS.enc.Utf8.stringify(decrypt).toString();
    },

 Click login 
// RSA encryption 
   let RSApublicKeyData = this.encryptRSA(
      this.loginForm.passwords,
      this.publicKey
    );
    // AES encryption 
    let AESPassword = this.encrypt(
      RSApublicKeyData,
      this.loginForm.symmetricKey
    );

copyright notice
author[囍囍囍囍囍囍囍囍囍囍 A],Please bring the original link to reprint, thank you.
https://en.qdmana.com/2022/119/202204290621251449.html