How to decrypt message with CryptoJS AES. I have a working Ruby example

后端 未结 5 2000
萌比男神i
萌比男神i 2020-12-01 01:57

I\'m able to decrypt AES encrypted message with Ruby like this:

require \'openssl\'
require \'base64\'

data = \"IYkyGxYaNgHpnZWgwILMalVFmLWFgTCHCZL9263NOcfS         


        
5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-01 02:05

    encryptWithCryptoJS(plainText: string): string {
        const key = CryptoJS.enc.Utf8.parse("hf8685nfhfhjs9h8");
        const iv1 = CryptoJS.enc.Utf8.parse("hf8685nfhfhjs9h8");
        const encrypted = CryptoJS.AES.encrypt(plainText, key, {
            keySize: 16,
            iv: iv1,
            mode: CryptoJS.mode.ECB,
            padding: CryptoJS.pad.Pkcs7
        });
    
        return encrypted + "";
    }
    
    decryptionWithCryptoJS(cipher: string): string {
        const key = CryptoJS.enc.Utf8.parse("hf8685nfhfhjs9h8");
        const iv1 = CryptoJS.enc.Utf8.parse("hf8685nfhfhjs9h8");
        const plainText = CryptoJS.AES.decrypt(cipher, key, {
            keySize: 16,
            iv: iv1,
            mode: CryptoJS.mode.ECB,
            padding: CryptoJS.pad.Pkcs7
        });
    
        return plainText.toString(CryptoJS.enc.Utf8);
    }
    

提交回复
热议问题