Apr 22nd, 2010, 07:18 PM
[VB6] Hide Your Secrets the Easy Way!
One of the things we run into now and then is the need to bury passwords or other secrets within our programs. Quite often we'll do something like encrypt the "secret" data as strings and use decryption logic at runtime to extract those actual "secret" values.
But where do you do the encryption in the first place? Use a separate program and then copy/paste in the encrypted text? And how about later when you need to change such values and recompile? I hope you kept your little encryption program handy too.
Here I offer an idea that came to me today: why not make the VB6 IDE do the encryption for you at design time? Then you can enter your secrets in plaintext when working on the program. No need for that second encryption program!
In this case I have a demo UserControl I call ScrambleProps. It's only purpose is to hold a series of properties in its PropertyBag in encrypted form and decrypt them when your instance gets loaded. Here I just put in three simple properties: URL, User, and PW.
You can change these to whatever properties you want to store encrypted. I recommend you replace the simple Scramble() routine I have in there with something a little stronger too of course.
Easy and Secret
If you compile this demo and look at the EXE with a hex viewer you won't find the plaintext values in there anywhere. Actually even if you look at the text of the .FRM file of the Form hosting ScrambleProps you'll only see the encrypted data!
But when you run the program it will extract the decrypted values and display them in the Form.
You enter your plaintext values... in the IDE's properties window!
See the attached screenshot.
Last edited by dilettante; Apr 23rd, 2010 at 09:40 PM.
Tags for this Thread
Click Here to Expand Forum to Full Width
Survey posted by VBForums.