AES Decryption is not working as expected.

I am using CryptoJS v3.1.2 for AES Encryption/Descryption.  I am facing problem in decryption. Encrypted value is getting from other system.

Encrypted Value : ul1tu6I0tLcfOYAW3Yug0HNP9sKo7O2AUuMLQjs62TOE5g0v9VTzB21EKdSAvlSM

Password :

r16glPt7vyO6g22KH4JcpzUIdnUXIy5p

Required decrypted value:

rWu2OrffvBucBhdbxHoP6PWM6n7aHmSJ2/K0IcR/l8E=

 

Code I am using:

 

var encryptedsek = “ul1tu6I0tLcfOYAW3Yug0HNP9sKo7O2AUuMLQjs62TOE5g0v9VTzB21EKdSAvlSM”;
var password = “r16glPt7vyO6g22KH4JcpzUIdnUXIy5p”;

var decrypted = CryptoJS.AES.decrypt(encryptedsek, password, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
}).toString(CryptoJS.enc.Utf8)

 

I guess there is issue related to base64 but just can’t figure it out.

 

 

Rookie Asked on July 16, 2020 in SuiteScript.

The things that you will want to clarify are the encoding involved for the encrypted value and the decrypted value, and what they represent. The way you are using the encrypted value in CryptoJs means that it will be interpreted as a Open-SSL compatible format. If it is not, you want to create a CipherParams object. Keep in mind that that will probably involve parsing your encrypted text using an encoding.

Also be very wary about the difference between a secret key and a passphrase. A passphrase is a convenience method used to derive the bytes of a secret key. By default, CryptoJs uses the same passphrases as OpenSSL. If you are working with secret keys and not passphrases, then your secret key has been encoded and you need to use one of CryptoJs’s encoding to parse it as bytes (WordArray in Crypto Js terms)

on July 16, 2020.
Add Comment
1 Answer(s)

Hi,

It’s really difficult to assist without knowing exactly what encryption mechanism is being used on the other system.

Also, I think you might have more luck on a CryptoJS forum or Stack Overflow on this subject and I found this which might be helpful:

https://stackoverflow.com/questions/14958103

In particular, it’s not clear whether any of your values are Base64 encoded and whether there’s a salt / initialisation vector.

Equally, I’d be happy to assist further if you can provide any further details about how the source system is encrypting the value.

Thanks,

Chris

Intermediate Answered on July 16, 2020.

Source system has provided Java code which they are using for decryption. Hope this will help.

 

public static String decrptyBySyymetricKey(String encryptedSek, byte[] appKey)
{
Key aesKey = new SecretKeySpec(appKey, “AES”); // converts bytes(32 byte random generated) to key
try {
Cipher cipher = Cipher.getInstance(“AES/ECB/PKCS5Padding”); // encryption type = AES with padding PKCS5
cipher.init(Cipher.DECRYPT_MODE, aesKey); // initiate decryption type with the key
byte[] encryptedSekBytes = Base64.decodeBase64(encryptedSek); // decode the base64 encryptedSek to bytes
byte[] decryptedSekBytes = cipher.doFinal(encryptedSekBytes); // decrypt the encryptedSek with the initialized cipher containing the key(Results in bytes)
String decryptedSek = Base64.encodeBase64String(decryptedSekBytes); // convert the decryptedSek(bytes) to Base64 StriNG
return decryptedSek; // return results in base64 string
}catch(Exception e)
{
return “Exception; “+e;
}
}

 

I gone through online tool https://www.devglan.com/online-tools/aes-encryption-decryption which is decryption  as expected for my case.

RE: AES Decryption is not working as expected.

on July 16, 2020.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.
  • This site made possible by our sponsors:   Tipalti   Celigo   Limebox   Become a Sponsor