React Native crypto AES CBC加密

CryptoJS.AES.decrypt解密值是base64编码!!!切记切记!坑死宝宝了

import CryptoJS from 'crypto-js';

let key = CryptoJS.enc.Utf8.parse('1234567890987654');
let iv = CryptoJS.enc.Utf8.parse("0987654321234567")

//解密方法
export const decrypt = (word) => {
    console.info('sss :' + word)
    let encryptedHexStr = CryptoJS.enc.Hex.parse(word);
    console.info('sss2 :' + encryptedHexStr)
    let decrypt = CryptoJS.AES.decrypt(word, key, {
        iv: iv,
        mode: CryptoJS.mode.CBC,
        padding: CryptoJS.pad.Pkcs7
    });
    console.info(' decrypt str :' + decrypt)

    let decryptedStr = CryptoJS.enc.Utf8.stringify(decrypt);
    console.info(' decrypt :' + decryptedStr)
    return decryptedStr
}

//加密方法
export const encrypt = (word) => {
    // let srcs = CryptoJS.enc.Utf8.parse(word);
    let encrypted = CryptoJS.AES.encrypt(word, key, {iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7});
    console.info(' encrypt :' + encrypted.ciphertext.toString())
    console.info(' encrypt encrypted:' + encrypted)
    return encrypted.toString();
}

你可能感兴趣的:(React Native crypto AES CBC加密)