I would like to try porting this code b4a in b4j, I can not find the library for the Cipher type. Can I have a help?
thank you all
Sub InitializeCipher(c As Cipher, transformation As String)
Dim r As Reflector
Dim o As Object = r.RunStaticMethod("javax.crypto.Cipher", "getInstance", Array(transformation, "BC"), _
Array As String("java.lang.String", "java.lang.String"))
r.Target = c
r.SetField2("cipher", o)
End Sub
Sub EncryptMobile(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
InitializeCipher(c, "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
thank you all
Sub InitializeCipher(c As Cipher, transformation As String)
Dim r As Reflector
Dim o As Object = r.RunStaticMethod("javax.crypto.Cipher", "getInstance", Array(transformation, "BC"), _
Array As String("java.lang.String", "java.lang.String"))
r.Target = c
r.SetField2("cipher", o)
End Sub
Sub EncryptMobile(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
InitializeCipher(c, "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