B4J Question Help for find library for type Cipher

Gnappo jr

Active Member
Licensed User
Longtime User
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
 

Gnappo jr

Active Member
Licensed User
Longtime User
You need the Encryption library from B4A. It should work fine with B4J.
Thanks for the prompt reply, i tried the b4a library as suggested and i added the jReflection 1.2 library but i get the following error

Dim o As Object = r.RunStaticMethod("javax.crypto.Cipher", "getInstance", Array(transformation, "BC"), _
Array As String("java.lang.String", "java.lang.String"))

java.security.NoSuchProviderException: No such provider: BC
at javax.crypto.Cipher.getInstance(Cipher.java:593)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4j.agraham.reflection.Reflection.RunStaticMethod(Reflection.java:994)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:612)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:226)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:159)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:90)
at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:61)
at b4j.example.main._initializecipher(main.java:182)
 
Upvote 0
Top