B4J Question How to encrypt with B4J and decrypt with VBA ?

amorosik

Expert
Licensed User
I created a web server in B4J for receiving requests from a program created with Microsoft Access
The sending of requests from Access to the B4J web server takes place correctly and also the responses
Now I would like to pass some encrypted data, using routines like at this link, which shows an example of encryption and decryption in B4J code

B4X:
#AdditionalJar: bcprov-jdk15on-154
Sub Process_Globals
    
End Sub

Sub AppStart (Args() As String)
    Dim p As String = "123456"
    Dim s As String = "top secret"
    Dim enc As String = Encrypt(s, p)
    Log(enc)
    Dim dec As String = Decrypt(enc, p)
    Log(dec)
End Sub

Private Sub Encrypt (Text As String, Password As String) As String
    Dim c As B4XCipher
    Dim b() As Byte = c.Encrypt(Text.GetBytes("utf8"), Password)
    Dim su As StringUtils
    Return su.EncodeBase64(b)
End Sub

Private Sub Decrypt(EncryptedText As String, Password As String) As String
    Dim c As B4XCipher
    Dim su As StringUtils
    Dim enc() As Byte = su.DecodeBase64(EncryptedText)
    Dim dec() As Byte = c.Decrypt(enc, Password)
    Return BytesToString(dec, 0, dec.Length, "utf8")
End Sub

The question is: how to make a routine in vba that can correctly decrypt the string encrypted by the Encrypt routine in B4J?
And similarly, how to make a procedure in vba to encrypt a string so that once decrypted by the Decrypt procedure as in the link above, the string appears as original?
 

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
You can't, the B4xCipher uses standard encryption but doesn't give you the salt that is used to encrypt. you need to use the other encryption library. the steps taken to encrypt/decrypt should be the same for any language
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
I don't know how but theoretically it is possible since B4XCipher is compatible with PHP through OpenSSL. If OpenSSL is installed in PC, maybe VBA can access the DLL or COM object.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Upvote 0
Top