B4J Question Encryption Help

rfresh

Well-Known Member
Licensed User
Longtime User
I'm trying to use some sample code (below) but am getting an error. I have checked the Encryption Lib for use. The example code came from Erel.

B4J line: 34
Dim b() As Byte = c.Decrypt(EncryptedData, passwo
javac 1.8.0_161
src\b4j\example\main.java:75: error: cannot access DataLengthException
_b = _c.Decrypt(_encrypteddata,_password);
^
class file for org.bouncycastle.crypto.DataLengthException not found
1 error

B4X:
#Region Project Attributes 
    #MainFormWidth: 600
    #MainFormHeight: 600 
#End Region

Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form

End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
    MainForm.Show

    Dim encryptedData() As Byte = EncryptText("confidential", "123456")
    Log(DecryptText(encryptedData, "123456"))
   
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

Sub EncryptText(text As String, password As String) As Byte()
    Dim c As B4XCipher
    Return c.Encrypt(text.GetBytes("utf8"), password)
End Sub

Sub DecryptText(EncryptedData() As Byte, password As String) As String
    Dim c As B4XCipher
    Dim b() As Byte = c.Decrypt(EncryptedData, password)
    Return BytesToString(b, 0, b.Length, "utf8")
End Sub
 

Similar Threads

Top