When trying to decrypt a Hex String in Java, I am able to decrypt the string but because the original data which was encrypted is not a String but actually 32 bit hexadecimal values.
The encrypted hex string is "4ba3442d4bc3baf5126b7b271b359e42", and the key used here is "ac00ac00ac00ac00ac00ac00ac00ac00"
The output which im supposed to get as retrieve from aes.online-domain-tools.com is "× z X . b 3 ý . ä g í ý b Þ ." but as seen from this String, only zXb3gb is of a normal ASCII character and the others are the extended characters which in return becomes a � in the console which carries a int value of 65533 which in turn is not correct for my original data.
But if we see the output from aes.online-domain-tools.com, the ASCII VALUES of the extended ASCII characters IS the correct values of the original data but because it is not a normal ASCII character but an extended character, it becomes a � with value 65533 which will give me the wrong value while being casted to integer.
I was wondering rather than decrypting it to a String, am I able to directly decrypt the hex string into the hex string rather than decrypt to string and cast to int.
Currently this is my decryption code:
public static String decrypt(String strToDecrypt)
{
char[] ch=strToDecrypt.toCharArray();
System.out.println("Test: " + ch);
try
{
Cipher cipher2 = Cipher.getInstance("AES/ECB/NoPadding");
cipher2.init(Cipher.DECRYPT_MODE, secretKey);
setDecryptedString(new String(cipher2.doFinal(Hex.decodeHex(ch)))); // Output as String eg: testingone
}
catch (Exception e)
{
System.out.println("Error while decrypting: "+e.toString());
}
return null;
}
And this is the block of code I use to cast it to INT to retrieve the original value:
System.out.println("String To Decrypt : " + strToDecrypt);
final String decryptedString = getDecryptedString();
char[] asciiLine = decryptedString.toCharArray();
for (char ch:asciiLine)
{
System.out.println("Decrypted : " + (int)ch+" ");
}
System.out.println("TestDecrypted : " + test.getDecryptedString());
System.out.println("StringDecrypted : " + decryptedString);
System.out.println("DecodeDecrypted : " + Integer.decode(decryptedString));