I believe this is a snippet from androidsnippets.org - why this isn\'t funcioning on Android 2.3? How to fix it?
Error
NickT says: "is going to give the same result of 3 for strings of length 6 and 7 (say)" I suppose that length of HEX string in that case is always EVEN number (see function appendHex)
Two points:
1) The toByte() method isn't clear what it's trying to do, but I'll bet it's wrong, as the line
int len = hexString.length()/2;
is going to give the same result of 3 for strings of length 6 and 7 (say)
2) You can't rely on converting stings to byte arrays without specifying the Charset to use. Different locales and different run machines may have different default Charsets. You should probably use str.getBytes("UTF8") in the algorithm.
It's problem with BouncyCastle (BouncyCastle AES error when upgrading to 1.45).
What I have found is that this results in two different values for BC 1.34 vs 1.45.
I couldn't find the solution, yet...