Unable to decrypt string encrypted by the cryptString function | Community
Skip to main content
Level 2
August 12, 2020
Solved

Unable to decrypt string encrypted by the cryptString function

  • August 12, 2020
  • 1 reply
  • 3868 views

I am trying to decrypt using Java a string encrypted by the cryptString function in Adobe Campaign Classic.

 

 

 

var encryptedString = cryptString (“helloworld”, “{secretKey}”, false);

 

 

I have observed the encrypted string always starts with an @ and is 1 character longer than if I encrypt the same string using Java.

 

The test Java decrypt function looks like:

 

 

 

public static void main( String[] args ) throws Exception { String decryptedString = decrypt("{encryptedString}", "{secretKey}"); System.out.println(decryptedString); } public static String decrypt(String encrypted, String secretKey) throws Exception { try { SecretKeySpec skeySpec = new SecretKeySpec(secretKey.getBytes("UTF-8"), "AES"); Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING"); cipher.init(Cipher.DECRYPT_MODE, skeySpec, new IvParameterSpec(new byte[16])); byte[] original = cipher.doFinal(Base64.decodeBase64(encrypted)); System.out.println(new String(original)); } catch (Exception ex) { ex.printStackTrace(); } return null; }

 

 

 

 

When I run this I get the error:

javax.crypto.BadPaddingException: Given final block not properly padded. Such issues can arise if a bad key is used during decryption.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by danc13675873

Hi Milan. This didn't work using DESede/CBC/NoPadding. The documentation says the encryption used by Adobe Campaign is AES / CBC with a null IV.

 

https://docs.adobe.com/content/help/en/campaign-classic/technicalresources/api/f-cryptString.html

Remarks

Encryption takes place according to the following method:
  • The unicode character string is transformed into a UTF-8 string.
  • A check character is added at the end.
  • This string is encrypted using the AES algorythm in Cipher Block Chaining (CBC) mode with a null initialization vector. If no key is provided as a parameter, the instance key is used.
  • The encrypted block is then converted into base 64.
Decryption is carried out using the decryptString function.

1 reply

Milan_Vucetic
Level 9
August 13, 2020

Hi @danc13675873

You may use "DESede/ECB/NoPadding" or  "DESede/CBC/NoPadding" instead.

Regards,

Milan

danc13675873AuthorAccepted solution
Level 2
August 13, 2020

Hi Milan. This didn't work using DESede/CBC/NoPadding. The documentation says the encryption used by Adobe Campaign is AES / CBC with a null IV.

 

https://docs.adobe.com/content/help/en/campaign-classic/technicalresources/api/f-cryptString.html

Remarks

Encryption takes place according to the following method:
  • The unicode character string is transformed into a UTF-8 string.
  • A check character is added at the end.
  • This string is encrypted using the AES algorythm in Cipher Block Chaining (CBC) mode with a null initialization vector. If no key is provided as a parameter, the instance key is used.
  • The encrypted block is then converted into base 64.
Decryption is carried out using the decryptString function.
Level 3
April 10, 2023

@danc13675873 

@milan_vucetic 

 

Is there a way to use a valid IV here or some other OOTB method to use?