I have written a B4A application that sends data in XML format to a webservice written in vb.net.
For safety data sent is encrypted and decrypted upon receipt by the webservice.
To encrypt the data I use the following B4A sub:
To decrypt the data I use the following vb.net code:
Until now everything worked properly.
Today I tried the app on a device Android 6.0.1 and I can no decrypt data.
I have noticed that the encrypted string with an Android 5.0.2 device is different from that encrypted with a device 6.0.1.
The first is successfully decrypted the second is not.
What might be this anomaly?
For safety data sent is encrypted and decrypted upon receipt by the webservice.
To encrypt the data I use the following B4A sub:
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(8, 8, 2, 10, 12, 12, 28, 5) ' 16 bytes for AES
c.Initialize("DESEDE/CBC/PKCS5Padding")
c.InitialisationVector = iv
kg.Initialize("DESEDE")
kg.KeyFromBytes(bconv.StringToBytes("XXXX000011Ix2010","ASCII"))
data = bconv.StringToBytes(dataToEncrypt, "ASCII")
data = c.Encrypt(data, kg.Key, True)
Return B64.EncodeBtoS(data, 0, data.Length)
End Sub
To decrypt the data I use the following vb.net code:
B4X:
Private Function Decrypt(encryptedData As String) As String
Dim buffer As Byte() = System.Convert.FromBase64String(encryptedData)
Dim des As TripleDESCryptoServiceProvider = New TripleDESCryptoServiceProvider()
des.IV = New Byte() {8, 8, 2, 10, 12, 12, 28, 5}
des.Key = ASCIIEncoding.ASCII.GetBytes("XXXX000011Ix2010")
Dim result As String = Encoding.ASCII.GetString(des.CreateDecryptor().TransformFinalBlock(buffer, 0, buffer.Length))
des.Clear()
Return result
End Function
Until now everything worked properly.
Today I tried the app on a device Android 6.0.1 and I can no decrypt data.
I have noticed that the encrypted string with an Android 5.0.2 device is different from that encrypted with a device 6.0.1.
The first is successfully decrypted the second is not.
What might be this anomaly?