iOS Question AES Encryption - different result compared to B4A ???

olivere

Member
Licensed User
Longtime User
Hello,
I need to implement AES enryption as following in B4A.
B4A part works and the result can be deciphered as well (using a decrypt routine on a PC).

Now I tried to Iranslate the encyrption method to B4I, but the result is not the same result as produced by the B4A code, thus the result can not be deciphered on the PC.
Hope somebody can help..

Thank you and kind regards
Oliver

B4X:
Sub AES_Encrypt(inputB() As Byte, IV As String, pass As String) As String
    Dim su As StringUtils
    Dim sb As ByteConverter
    Dim passB() As Byte = sb.HexToBytes(pass)
    Dim IVb() As Byte = sb.HexToBytes(IV)
    Dim C As Cipher
 #if b4a
    Dim kg As KeyGenerator
    kg.Initialize("AES") 'Yes, AES only
    kg.KeyFromBytes(passB)
    C.Initialize("AES/CBC/ISO10126Padding")
    C.InitialisationVector = IVb
    Dim datas() As Byte = C.Encrypt(inputB, kg.Key,  True)
#else if b4i
    Dim bsalt() As Byte
    Dim iOption As Int = Bit.Or(0,C.OPTION_PKCS7Padding)
    Dim bkey() As Byte=C.GenerateKey(  passB, "SHA-256", bsalt,0)
    Dim datas() As Byte = C.Encrypt2(inputB, bkey,"AES", IVb,iOption)
#endif

    Return su.EncodeBase64(datas)
End Sub
 

olivere

Member
Licensed User
Longtime User
. The first one is that you are hashing the key in B4i. Remove line 17 and use passB directly.
Thank you very much, that was the solution !šŸ‘

Concering padding: what would be equivalent to ISO10126Padding from B4A ?
 
Upvote 0
Top