Hi,
I am trying to Decrypt a AES (AES-128) message but having a issue in doing so.
My Code:
The error shows:
Line 29 is Dim b() As Byte = c.Decrypt(su.DecodeBase64(EncryptedData), "123456")
The string is sent to me from another device (not from a B4X project, so I have no control on how it gets encrypted).
The Password is a base64Binary and I used 123456 as the password.
Any ideas on what I am doing wrong ?
I am trying to Decrypt a AES (AES-128) message but having a issue in doing so.
My Code:
B4X:
'Non-UI application (console / server application)
#Region Project Attributes
#CommandLineArgs:
#MergeLibraries: True
#AdditionalJar: bcprov-jdk15on-154
#End Region
Sub Process_Globals
End Sub
Sub AppStart (Args() As String)
DecryptMessage
StartMessageLoop
End Sub
'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
Return True
End Sub
Public Sub DecryptMessage
Dim EncryptedData As String = "$�H(��<n��U���s�ޒKt|�&<,�V_���uUtB���;_p(�b���p��ӧ�����"
Private su As StringUtils
Dim c As B4XCipher ' jB4XEncryption 1.00
Dim b() As Byte = c.Decrypt(su.DecodeBase64(EncryptedData), "123456")
Log(BytesToString(b, 0, b.Length, "utf8"))
End Sub
The error shows:
Waiting for debugger to connect...
Program started.
Error occurred on line: 29 (Main)
java.io.IOException: Bad Base64 input character decimal 36 in array position 0
at anywheresoftware.b4a.objects.Base64.decode(Base64.java:1204)
at anywheresoftware.b4a.objects.Base64.decode(Base64.java:1259)
at anywheresoftware.b4a.objects.Base64.decode(Base64.java:1227)
at anywheresoftware.b4a.objects.StringUtils.DecodeBase64(StringUtils.java:36)
at b4j.example.main._decryptmessage(main.java:103)
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:497)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:613)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:228)
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:497)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:90)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:93)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:77)
at b4j.example.main.main(main.java:29)
Line 29 is Dim b() As Byte = c.Decrypt(su.DecodeBase64(EncryptedData), "123456")
The string is sent to me from another device (not from a B4X project, so I have no control on how it gets encrypted).
The Password is a base64Binary and I used 123456 as the password.
Any ideas on what I am doing wrong ?
Last edited: