G gregmatthews Member Licensed User Mar 27, 2017 #1 Hi, I need to decrypt an AES encrypted string within B4A, I have the key and IV used for encryption. I am having trouble setting up Cipher to decrypt. Code: Copy iv = Array As Byte(1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6) ' 16 bytes for AES mykey = Array As Byte(1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6) ' 16 bytes for AES c.Initialize("AES") c.InitialisationVector = iv kg.KeyFromBytes(mykey) The last line creates a Java exception: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String javax.crypto.KeyGenerator.getAlgorithm()' on a null object reference Any ideas? G.
Hi, I need to decrypt an AES encrypted string within B4A, I have the key and IV used for encryption. I am having trouble setting up Cipher to decrypt. Code: Copy iv = Array As Byte(1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6) ' 16 bytes for AES mykey = Array As Byte(1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6) ' 16 bytes for AES c.Initialize("AES") c.InitialisationVector = iv kg.KeyFromBytes(mykey) The last line creates a Java exception: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String javax.crypto.KeyGenerator.getAlgorithm()' on a null object reference Any ideas? G.
G gregmatthews Member Licensed User Mar 27, 2017 #2 Doh! sorry for the fire drill - I'd not initialized the algorithm for the key generator Code: Copy kg.Initialize("AES") Upvote 0
Doh! sorry for the fire drill - I'd not initialized the algorithm for the key generator Code: Copy kg.Initialize("AES")
G gregmatthews Member Licensed User Mar 27, 2017 #3 Oh, so close now, all the right characters decrypted, though not necessarily in the right positions... Code: Copy Dim bconv As ByteConverter Dim data(0) As Byte data = B64.DecodeStoB(encryptedData) decryptedData = c.Decrypt(data, kg.Key, True) decryptedString = bconv.StringFromBytes(decryptedData, "ASCII") Results in decrypted data having an array of bytes with the Ascii characters interspersed with zeroes decryptedString is then the correct characters, interspersed with nulls I've tried UTF-8 and ASCII in the StringFromBytes, both give the interspersed nulls I've tried UTF-16 and get Chinese What am I missing/not understanding? (Also tried the above with littlendian set to true) Last edited: Mar 27, 2017 Upvote 0
Oh, so close now, all the right characters decrypted, though not necessarily in the right positions... Code: Copy Dim bconv As ByteConverter Dim data(0) As Byte data = B64.DecodeStoB(encryptedData) decryptedData = c.Decrypt(data, kg.Key, True) decryptedString = bconv.StringFromBytes(decryptedData, "ASCII") Results in decrypted data having an array of bytes with the Ascii characters interspersed with zeroes decryptedString is then the correct characters, interspersed with nulls I've tried UTF-8 and ASCII in the StringFromBytes, both give the interspersed nulls I've tried UTF-16 and get Chinese What am I missing/not understanding? (Also tried the above with littlendian set to true)
G gregmatthews Member Licensed User Mar 27, 2017 #4 Oh, I'm so ashamed, I've had to knife and fork it by copying every 2nd byte to a new array and then convert that to a string. I hope that approach is so offensive to someone's programming sensibilities that can help me correct my aberrant code. Upvote 0
Oh, I'm so ashamed, I've had to knife and fork it by copying every 2nd byte to a new array and then convert that to a string. I hope that approach is so offensive to someone's programming sensibilities that can help me correct my aberrant code.