Looking for a simple text encryption/decryption VB6 code. Ideally, the solution should accept (text, password)
arguments and produce readable output (without any special characters), so it can be used anywhere without encoding issues.
There are lots of code available for .NET, but not really much I can find for legacy VB6. Only this I've found so far: http://www.devx.com/vb2themax/Tip/19211
MD5sum the the text and password together as a one way hash (and then to check, you encrypt again and compare with the stored hash. (This won't work if you MUST decrypt it again though)
Here's my encryption class. I use several constants to define the encryption key because in my mind it's a little more secure from someone trying to decompile the code to find it. Cryptography isn't my thing so maybe I'm kidding myself. Anyway, I used this class in an ActiveX dll called from other programs to do encryption and the reverse in a separate dll for decryption. I did it this way so people who shouldn't be seeing encrypted data don't even have the dll to do the decrypting. Change the key constants to what you want (5 long). I use a mix including unprintable characters and it has worked well for me so far. The CAPICOM is part of Windows® so you don't have to distribute.
I'm using RC4 implementation like this
Command1
outputs this:You might need better error handling on
FromHexDump
though.Update (2018-05-04)
For much stronger AES 256-bit encryption (in ECB mode) and proper handling of unicode texts/passwords you can check out Simple AES 256-bit password protected encryption as implemented in
mdAesEcb.bas
module (~380 LOC).