Hello,
I've got an Android app that comunicates with an AspNet web service; I am creating the same app for IOS with B4i. But I am not able to convert the encryption routine I used from B4a to B4i..
Here is the working well b4a routine:
I have converted it in B4i in this way:
But in this line I always get error:
output = bconv.StringFromBytes(data2, "UTF8")
Using another encoding works fine, but then my webservice is not able to decrypt the content; for example:
output = bconv.StringFromBytes(data2, "ISO-8859-1")
What am I doing wrong?
Thanks
I've got an Android app that comunicates with an AspNet web service; I am creating the same app for IOS with B4i. But I am not able to convert the encryption routine I used from B4a to B4i..
Here is the working well b4a routine:
B4X:
Sub Encrypt(dataToEncrypt As String, key 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(1, 2, 3, 4, 5, 6, 7, 8) 'not the original iV
c.Initialize("DESEDE/CBC/PKCS5Padding")
c.InitialisationVector = iv
kg.Initialize("DESEDE")
kg.KeyFromBytes(bconv.StringToBytes(key,"UTF8"))
data = bconv.StringToBytes(dataToEncrypt, "UTF8")
data = c.Encrypt(data, kg.key, True)
Return B64.EncodeBtoS(data, 0, data.Length)
End Sub
I have converted it in B4i in this way:
B4X:
Sub Encrypt(dataToEncrypt As String, key As String) As String
Dim c As Cipher
Dim bconv As ByteConverter
Dim opzioni As Int
Dim data(0) As Byte
Dim data2(0) As Byte
Dim iv(0) As Byte
iv = Array As Byte(1, 2, 3, 4, 5, 6, 7, 8) 'not the original iV
Dim kgBytes() As Byte
Dim pw() As Byte
Dim output As String
pw = bconv.StringToBytes(key, "UTF8")
kgBytes = c.GenerateKey(pw, "SHA-1", iv, 1)
data = bconv.StringToBytes(dataToEncrypt, "UTF8")
opzioni = Bit.OR(c.OPTION_ECBMode, c.OPTION_PKCS7Padding)
data2 = c.Encrypt2(data, kgBytes, "3DES", iv, opzioni)
output = bconv.StringFromBytes(data2, "UTF8")
Return output
End Sub
But in this line I always get error:
output = bconv.StringFromBytes(data2, "UTF8")
Using another encoding works fine, but then my webservice is not able to decrypt the content; for example:
output = bconv.StringFromBytes(data2, "ISO-8859-1")
What am I doing wrong?
Thanks