How to use the TripleDES function from crypto-js

Find comprehensive JavaScript crypto-js.TripleDES code examples handpicked from public code repositorys.

0
1
2
3
4
5
6
7
8
9
var CryptoJS = require('crypto-js')

function I(X, l) {
    var C = X
        , q = CryptoJS.enc.Utf8.parse(C)
        , v = CryptoJS.TripleDES.decrypt(l, q, {
            'mode': CryptoJS.mode.ECB,
            'padding': CryptoJS.pad.Pkcs7
        });
    return v.toString(CryptoJS.enc.Utf8);
fork icon12
star icon55
watch icon2

15
16
17
18
19
20
21
22
23
24

function encrypt(data) {
    let algorithm = 'des-128-cbc'
    let passwd = '{1dYgqE)h9,R)hKqEcv4]k[h'
    let iv = '01234567'
    str = cryptojs.TripleDES.encrypt("" + data, cryptojs.enc.Utf8.parse(passwd), {
        iv: cryptojs.enc.Utf8.parse(iv),
        mode: cryptojs.mode.CBC,
        padding: cryptojs.pad.Pkcs7
    })
fork icon10
star icon15
watch icon2

27
28
29
30
31
32
33
34
35
36
   *  npm install --save crypto-js
   *  解密方法
   *  https://www.jianshu.com/p/76ee794e34d6
   */
CBCDecrypt(word) {
  const decrypted = CryptoJS.TripleDES.decrypt(word,
    key, {
    mode: CryptoJS.mode.CBC,
    padding: CryptoJS.pad.Pkcs7,
    iv: iv
fork icon2
star icon8
watch icon2

+ 11 other calls in file

13
14
15
16
17
18
19
20
21
22
  ]);
  return encryptedData.toString('base64');
};
// const signingData = (str, key) => {
//   let keyHex = CryptoJS.enc.Base64.parse(key);
//   return CryptoJS.TripleDES.encrypt(str, keyHex, {
//     iv: keyHex,
//     mode: CryptoJS.mode.ECB,
//     padding: CryptoJS.pad.Pkcs7,
//   }).toString();
fork icon2
star icon2
watch icon1

28
29
30
31
32
33
34
35
36

export function mac3des(encKey: Uint8Array, data: Uint8Array, iv: Uint8Array) : Uint8Array {
  let dataWArray = CryptoJS.lib.WordArray.create(data);
  let sessionEncKeyWArray = CryptoJS.lib.WordArray.create(resizeKey24(encKey));
  let ivWArray = CryptoJS.lib.WordArray.create(iv);
  let encDataWArray = CryptoJS.TripleDES.encrypt(dataWArray, sessionEncKeyWArray, {iv: ivWArray, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.NoPadding});
  let encData = CryptoUtils.wordArrayToByteArray(encDataWArray.ciphertext);
  return encData.subarray(16, 24);
}
fork icon0
star icon5
watch icon2

+ 7 other calls in file

104
105
106
107
108
109
110
111
112
113
},
aes() {
  return CryptoJS.AES.encrypt(this.text, this.serect).toString();
},
tripledes() {
  return CryptoJS.TripleDES.encrypt(this.text, this.serect).toString();
},
rc4() {
  return CryptoJS.RC4.encrypt(this.text, this.serect).toString();
},
fork icon0
star icon1
watch icon1

+ 17 other calls in file

24
25
26
27
28
29
30
/**
 * @param {String} str string to decrypt
 * @returns {String} decrypted
 */
exports.decrypt = function ( str, pass ) {
    return CRYPTO.TripleDES.decrypt(str, pass).toString(CRYPTO.enc.Utf8);
}
fork icon3
star icon0
watch icon5

+ 3 other calls in file

63
64
65
66
67
68
69
70
71
72
    }
};

exports.decode3DES = function(cipherString, key) {
        try {
        return CryptoJS.TripleDES.decrypt(
            cipherString, 
            typeof key !== undefined ? key : this.key,
            this.cfg
        );
fork icon1
star icon0
watch icon2

+ 7 other calls in file