Android Question Is there a library or class that I can use to encrypt and decrypt string in both b4a, VB6, PHP at the same time?

Jim2025

Member
For example, I want to create a program under Windows with VB6 and a web page in PHP and also an application under Android and in three of them I need to encrypt or decrypt a string, but the problem is that I am looking for a library or class that can be used in these three programming languages. For example, I want to convert a string to a password in Android and decrypt the encrypted string inside VB6 or PHP, or for example, I want to encrypt a string in VB6 and decrypt the same encrypted string in Android. If the program worked with the Internet, there would be no need for these 3 modes, but since each one works independently, is there a way?

Is there a library or class that I can use to encrypt and decrypt in both Android and Visual Basic 6 and PHP at the same time?
I saw a sample library like AES or Base64 here, but these are only made for the B4A, it seems like the only way to make a common algorithm for all three.
Does anyone know of an example, library or class?
 
Solution
I also added the idea of reversing the base64 string. I think that's enough. It works for the purpose I had from the beginning. Friends, anyone can change the codes according to their own wishes. Good luck.

aeric

Expert
Licensed User
Longtime User
I suggest to replace VB6 with B4J.
You can use B4XEncryption (AES) and Encryption libraries for B4A, B4J, B4i and PHP.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
I don´t get it. you can use B4XEncryption in PHP?
I don´t think you can add jar files to PHP
I mean that the AES-256 encryption works with B4X, PHP, .NET.

B4R too:

I never tested with VB6 or VBA:
 
Upvote 0

ddefrain

Member
Licensed User
Longtime User
I mean that the AES-256 encryption works with B4X, PHP, .NET.

B4R too:

I never tested with VB6 or VBA:
Yes it's true it works in .NET Android and iPhone at the same time, I'm sure about that
 
Upvote 0

emexes

Expert
Licensed User
I was going great with:


and had gotten as far as:

HTML:
Plaintext: This is a test!!
Key: 12345678901234567890123456789012
Ciphertext (hex): 241ABA29BEB18870C9FE8153F55D77B03FC0E3069D55045A7F5FAE6EAF9F763C

but then when I went to confirm that it was compatible with JB4XEncryption, I found that that uses 128-bit encryption and a password instead of a 32-byte (256-bit) key directly, so...

time for a cup of tea.
 
Last edited:
Upvote 0

Jim2025

Member
Thanks to the friends who sent answers. I had already mentioned most of these examples that I have seen, finally I had to design a simple example that works in the three languages (b4a, vb6, php) I want, I also tried to include support for Base64, Unicode, and UTF-8. in this case in offline mode that does not require the use of the Internet platform, Of course, it can also be used online. I created something that may be useful to friends. I also tried to do it without the need for complex libraries or ocx or activating special features such as the need to have SSL functions in php and the like. In addition to the three languages, I also tested it in the B4j environment, and it works. It will most likely be implemented in the VBA environment because many of the functions of the VBA environment can also be used inside VBA. Codes can also be converted to other languages.Now, for example, you can encrypt a text and use the encrypted phrase in another environment that needs to be decrypted, while the encryption and decryption algorithm is the same in all of them.Of course, these codes can be improved. For greater security, I tried to perform encryption and decryption operations in several places in a simple way, and the output is ultimately converted to a number.

Example use:

B4X:
input string: "aaadddf"
key: "1234"
output: "023900240702415023920239002407023910239602391023860249402494"

Now we can take this expression (output string), for example, into PHP, or into VB6 or B4J and convert it back to the original decrypted text.
output.jpg

 

Attachments

  • @Jim2025.rar
    123 KB · Views: 26
Last edited:
Upvote 0

emexes

Expert
Licensed User
I need to encrypt or decrypt a string

Do you need something standard, or just something simple that you can easily implement in a variety of languages and dialects?

Bear in mind that any encryption that uses a key (or passkey or password) is only going to be as strong as your ability to keep people from disassembling your program.

In fact, something you code yourself that isn't a standard encryption, has some added "security by obscurity".

You could, for example, use the sequence X(I + 1) = (X(I) * 17 + 31) Mod 8192 to generate a pseudo-random sequence of integers 0..8191, and then use Bit.And(X(I), 0xFF) to turn that into a pseudo-random sequence of bytes 0..255, and then use that as a cipher-pad.

In fact, if you start the sequence off with today's date eg X(0) = 20250309 Mod 8192 then you've got yourself a one-time cipher pad for each day.

Add some random salt and do the Xoring progressively and you've got something strong enough for our usual humble purposes.

Still crackable by somebody who can disassemble your program, though, but like I noted above, so is any method that uses a shared secret.

There is the small problem that the above sequence repeats after 8192 items, but as long as your messages are shorter than that... no problem. And if they're longer, well, it's still hard to crack, just less hard. Or we can find a longer sequence: I chose the above sequence because it fits easily inside 32-bit math, but is no problem to find a longer one like eg X(I + 1) = (X(I) * 153 + 160) Mod 0x40000 which give you a sequence of 262144 pseudo-random numbers.
 
Upvote 0

emexes

Expert
Licensed User
something simple

Just running it through Base64 encoding a few times will be enough to stump most people.

Reverse one of the intermediate Base64 strings to seal the deal.

B4X:
Sub ReverseBase64(X As String) As String
    Dim RX As String    'should probably use StringBuilder but we're going for simplicity first
    Dim Ch As Char
 
    For I = 0 To X.Length - 1
        Ch = X.CharAt(I)

        If Ch = "=" Then
            RX = RX & Ch    'padding stays at end of string
        Else
            RX = Ch & RX    'everything else is reversed by adding it at start of string
        End If
    Next
 
    Return RX
End Sub
 
Upvote 0

Jim2025

Member
I also added the idea of reversing the base64 string. I think that's enough. It works for the purpose I had from the beginning. Friends, anyone can change the codes according to their own wishes. Good luck.
 

Attachments

  • @Jim2025.rar
    124.1 KB · Views: 36
Upvote 0
Solution
Top