Blowfish decrypting hex encoded string

739 views Asked by At

I'm trying to decrypt Hex encoded string via Blowfish. But the result is different from the correct one.

String s="a1d0534e4baf9e670bde8670caee8b87"
String decKey = "R=U!LH$O2B#";
Cipher m_decrypt = Cipher.getInstance("Blowfish/ECB/PKCS5Padding");
m_decrypt.init(Cipher.DECRYPT_MODE, new SecretKeySpec(decKey.getBytes(),"Blowfish"));
byte[] decrypted = m_decrypt.doFinal(Hex.decodeHex(s.toCharArray()));

Correct result from site: c6 b7 8d 52 31 35 30 34 31 38 38 36 39 37 02 02

My result: -58 -73 -115 82 49 53 48 52 49 56 56 54 57 55

I check the correct byte array with mine on this site http://blowfish.online-domain-tools.com/

1

There are 1 answers

0
zaph On BEST ANSWER

The correect result: c6 b7 8d 52 31 35 30 34 31 38 38 36 39 37 02 02
is in hex encoding and contains two bytes of padding.

My result: -58 -73 -115 82 49 53 48 52 49 56 56 54 57 55
in in signed decimal encoding without the padding bytes.

They are the same value just in different encodings where "My result" has had the padding removed as is usual.