Sign in

How to use cryptojs plug-in to encrypt 3DES in Vue and output Base64

Jean edited in Thu, 01 Sep 2022

The project needs to encrypt the password, using 3DES encryption method, but the methods found on the Internet are output hex, and the project needs to output Base64

Use the link below to code the test online


key:key , ciphertext: 123456, output: balse64, result: 9ctfxkhihoy=


Then, in the same way, change the output Base64 to hex, and it becomes f5cb455e486284e6


I've tried to convert the encrypted text of hex to Base64. It doesn't seem to work

Related codes

function pswdEncryptByDES(string) {
  const KeyHex = CryptoJS.enc.Utf8.parse("key");  // key
  const encrypted = CryptoJS.TripleDES.encrypt(string, 
    KeyHex, {
      mode: CryptoJS.mode.ECB,
      padding: CryptoJS.pad.Pkcs7

  let hexstr = encrypted.ciphertext.toString();
  return hexstr;

The result is the encrypted text of hex

Is there any way to output Base64 directly like online encryption??

1 Replies
commented on Thu, 01 Sep 2022

Resolved. Will return at last encrypted.ciphertext.toString () changed to encrypted.toString () is enough encrypted.toString () returns the ciphertext of Base64

lock This question has been locked and the reply function has been disabled.