B4J Question AES128 ECB Decrypt

aaronk

Well-Known Member
Licensed User
Longtime User
Hi,

I am trying to decrypt a message using AES128 in ECB mode, and not CBC mode.

The data I am trying to decrypt is sent to my B4J as AES-128 in ECB mode, and that data I have put into a string called 'dataToDecrypt' in my code below.

When I run the following code I get the following error:


Line 83 is: decrypted = C.Decrypt(decrypted, kg.Key, False)

B4X:
Dim dataToDecrypt As String = "�q�!DAZ��R��:f/�Ŝ��h�U�0h�V��ƅHw��s�Č)�o�yZ��%v��_,"
   
    Dim kg As KeyGenerator
    Dim C As Cipher
    Dim decrypted() As Byte
    Dim BConv As ByteConverter
   
    decrypted = dataToDecrypt.GetBytes("UTF8")
 
    Dim Key As String = "0123456789ABCDEF" ' this is the same key that encrypted the string that was sent

    kg.Initialize("AES")
    kg.KeyFromBytes(Key.GetBytes("UTF8"))
     
    C.Initialize("AES/ECB/NoPadding") ' not 100% sure on the NoPadding part

    decrypted = C.Decrypt(decrypted, kg.Key, False)

    Log("Decrypt = " & BConv.StringFromBytes(decrypted, "UTF8"))

Anyone know where I have gone wrong ?
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…