B4J Question Encryption Help

Discussion in 'B4J Questions' started by rfresh, Apr 22, 2018.

  1. rfresh

    rfresh Well-Known Member Licensed 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

    Code:
    #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 StringAs Boolean
        
    Return True
    End Sub

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

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

    Roycefer Well-Known Member Licensed User

    Erel likes this.
  3. rfresh

    rfresh Well-Known Member Licensed User

    Got it...thanks...
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice