Hi, I need help to convert 2 routines from B4A to B4I:
I try to inspire from this code:
but the result is not the same.
I need to get routines that return exactly the same result because I can't modify both the B4A and web application that already work...
B4X:
Sub Encrypt(dataToEncrypt As String ) As String
Dim kg As KeyGenerator
Dim c As Cipher
Dim B64 As Base64
Dim bconv As ByteConverter
Dim data(0) As Byte
Dim iv(0) As Byte
iv = Array As Byte(211, 5, 233, 24, 55, 166, 7, 88)
c.Initialize("DESEDE/CBC/PKCS5Padding")
c.InitialisationVector = iv
kg.Initialize("DESEDE")
kg.KeyFromBytes(bconv.StringToBytes("5244067896183996","ASCII"))
data = bconv.StringToBytes(dataToEncrypt, "ASCII")
data = c.Encrypt(data, kg.Key, True)
Return B64.EncodeBtoS(data, 0, data.Length)
End Sub
Sub Decrypt(encryptedData As String ) As String
Dim kg As KeyGenerator
Dim c As Cipher
Dim B64 As Base64
Dim bconv As ByteConverter
Dim data(0) As Byte
Dim iv(0) As Byte
iv = Array As Byte(211, 5, 233, 24, 55, 166, 7, 88)
c.Initialize("DESEDE/CBC/PKCS5Padding")
c.InitialisationVector = iv
kg.Initialize("DESEDE")
kg.KeyFromBytes(bconv.StringToBytes("5244067896183996","ASCII"))
data = B64.DecodeStoB(encryptedData)
data = c.Decrypt(data, kg.Key, True)
Return bconv.StringFromBytes(data, "ASCII")
End Sub
I try to inspire from this code:
B4X:
Public Sub Encrypt(dataToEncrypt As String) As String
Dim PW As String = "5244067896183996"
Dim SU As StringUtils
Dim C As Cipher
Dim iOption As Int = Bit.Or(C.OPTION_PKCS7Padding,C.OPTION_ECBMode)
Dim bData() As Byte = C.Encrypt2(dataToEncrypt.GetBytes("ASCII"),PW.GetBytes("ASCII"),"AES",Null,iOption)
Return SU.EncodeBase64(bData)
End Sub
I need to get routines that return exactly the same result because I can't modify both the B4A and web application that already work...