Hello, I have encountered a very strange problem.
I use some functions to encrypt texts that have always worked well.
The functions are copied from a message from these forums. They have been working correctly for years. But not now.
In some new devices (tablets) the results are different.
These are the functions:
This is the code I am using to test.
And this is the result with one tablet and another.
I use some functions to encrypt texts that have always worked well.
The functions are copied from a message from these forums. They have been working correctly for years. But not now.
In some new devices (tablets) the results are different.
These are the functions:
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) ' 16 bytes for AES
c.Initialize("DESEDE/CBC/PKCS5Padding")
c.InitialisationVector = iv
kg.Initialize("DESEDE")
kg.KeyFromBytes(bconv.StringToBytes("1234567890123456","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) ' 16 bytes for AES
c.Initialize("DESEDE/CBC/PKCS5Padding")
c.InitialisationVector = iv
kg.Initialize("DESEDE")
kg.KeyFromBytes(bconv.StringToBytes("1234567890123456","ASCII"))
data = B64.DecodeStoB(encryptedData)
data = c.Decrypt(data, kg.Key, True)
'
Return bconv.StringFromBytes(data, "ASCII")
End Sub
Sub getEncoded( cCadena As String ) As String
Dim data() As Byte
Dim su As StringUtils
Dim encoded As String
'
data = cCadena.GetBytes("ASCII")
encoded = su.EncodeBase64(data)
'
Return (encoded)
End Sub
Sub getDecoded( cCadena As String ) As String
Dim data() As Byte
Dim su As StringUtils
Dim decoded As String
'
data = su.DecodeBase64(cCadena)
decoded = BytesToString(data, 0, data.Length, "ASCII")
'
Return (decoded)
End Sub
This is the code I am using to test.
B4X:
cHoInt = "Hi this Is a test."
cUsInt = "This Is the second line."
cPaInt = "And here the text ends."
Log("cHoInt: "&cHoInt)
Log("cUsInt: "&cUsInt)
Log("cPaInt: "&cPaInt)
cHoInt = uf.Encrypt(cHoInt)
cUsInt = uf.Encrypt(cUsInt)
cPaInt = uf.Encrypt(cPaInt)
Log("cHoInt: "&cHoInt)
Log("cUsInt: "&cUsInt)
Log("cPaInt: "&cPaInt)
cHoInt = uf.getEncoded(cHoInt)
cUsInt = uf.getEncoded(cUsInt)
cPaInt = uf.getEncoded(cPaInt)
Log("cHoInt: "&cHoInt)
Log("cUsInt: "&cUsInt)
Log("cPaInt: "&cPaInt)
Log("<<<")
cHoInt = uf.getDecoded(cHoInt)
cUsInt = uf.getdecoded(cUsInt)
cPaInt = uf.getdecoded(cPaInt)
Log("cHoInt: "&cHoInt)
Log("cUsInt: "&cUsInt)
Log("cPaInt: "&cPaInt)
cHoInt = uf.Decrypt(cHoInt)
cUsInt = uf.dEcrypt(cUsInt)
cPaInt = uf.dEcrypt(cPaInt)
Log("cHoInt: "&cHoInt)
Log("cUsInt: "&cUsInt)
Log("cPaInt: "&cPaInt)
And this is the result with one tablet and another.
cHoInt: Hi this Is a test.
cUsInt: This Is the second line.
cPaInt: And here the text ends.
cHoInt: 4H1xC4N9yngRoynRep9L2/OMePLBzbfQ
cUsInt: 4hDzX80C+KrJ4BTCPmp6NQzN0VKqnhjfakBF6kTM38I=
cPaInt: lDsPRRRH3CbRqfKd/qVFH/P2WPVRgHda
cHoInt: NEgxeEM0Tjl5bmdSb3luUmVwOUwyL09NZVBMQnpiZlE=
cUsInt: NGhEelg4MEMrS3JKNEJUQ1BtcDZOUXpOMFZLcW5oamZha0JGNmtUTTM4ST0=
cPaInt: bERzUFJSUkgzQ2JScWZLZC9xVkZIL1AyV1BWUmdIZGE=
<<<
cHoInt: 4H1xC4N9yngRoynRep9L2/OMePLBzbfQ
cUsInt: 4hDzX80C+KrJ4BTCPmp6NQzN0VKqnhjfakBF6kTM38I=
cPaInt: lDsPRRRH3CbRqfKd/qVFH/P2WPVRgHda
cHoInt: Hi this Is a test.
cUsInt: This Is the second line.
cPaInt: And here the text ends.
Please, someone who enlightens my mind.cHoInt: Hi this Is a test.
cUsInt: This Is the second line.
cPaInt: And here the text ends.
cHoInt: 8LqUm4ka+bZV97Ht47vPUMxFi+IOCOom
cUsInt: equI+tGF8Ekf4J3UuLsPRGmCny4+iOTxU+jz+mz4Rnk=
cPaInt: yS9U2DuvH5pLDMJ6Rj6zSYF/0EwYkxsM
cHoInt: OExxVW00a2ErYlpWOTdIdDQ3dlBVTXhGaStJT0NPb20=
cUsInt: ZXF1SSt0R0Y4RWtmNEozVXVMc1BSR21Dbnk0K2lPVHhVK2p6K216NFJuaz0=
cPaInt: eVM5VTJEdXZINXBMRE1KNlJqNnpTWUYvMEV3WWt4c00=
<<<
cHoInt: 8LqUm4ka+bZV97Ht47vPUMxFi+IOCOom
cUsInt: equI+tGF8Ekf4J3UuLsPRGmCny4+iOTxU+jz+mz4Rnk=
cPaInt: yS9U2DuvH5pLDMJ6Rj6zSYF/0EwYkxsM
cHoInt: Hi this Is a test.
cUsInt: This Is the second line.
cPaInt: And here the text ends.