B4J Question Encryption. Sample fails.

Discussion in 'B4J Questions' started by Karl Wagner, Jun 14, 2018.

  1. Karl Wagner

    Karl Wagner Member Licensed User


    I am trying this code, just as posted on this forum.
    It fails. I have attached a screenshot.


    Sub Process_Globals
    'These global variables will be declared once when the application starts.
        'These variables can be accessed from all modules.
        Dim cifro As B4XCipher
    End Sub

    Sub Globals
    'These global variables will be redeclared each time the activity is created.
        'These variables can only be accessed from this module.
    End Sub

    Sub Activity_Create(FirstTime As Boolean)

    End Sub

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

    Sub Decrypt(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

    Dim EncryptedData() As Byte = Encrypt("confidential""123456")
    Log(Decrypt(EncryptedData, "123456"))

    Attached Files:

    Last edited: Jun 14, 2018
  2. Erel

    Erel Administrator Staff Member Licensed User

  3. Karl Wagner

    Karl Wagner Member Licensed User

    Hi Erel,

    Thanks for writing.
    The code I posted is your code.
    It's a sample you posted on this forum.
    The screenshot displays the error.

  4. Erel

    Erel Administrator Staff Member Licensed User

    I know. However it makes it more difficult to read the post and it is not searchable. You should post it as text.

    I don't know where does the code you posted come from however it is B4A code.

    I ask again:
    Have you followed the 3 lines tutorial: https://www.b4x.com/android/forum/threads/jb4xencryption.48178/ ?

    It is really 3 lines. It wouldn't take you more than 2 minutes to read and understand your mistake.
  5. Karl Wagner

    Karl Wagner Member Licensed User

    Ok!, let me double check that link!
    My target will be B4A. Not for B4J.
    I was testing it on B4J to avoid transfer via bridge to the phone on B4A and have a quicker test cycle.

  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