HOWTO: Encrypt a String with Password SecurityLast reviewed: July 3, 1997Article ID: Q110308 |
The information in this article applies to:
SUMMARYIt is sometimes desirable to restrict the visibility of string constants within a Microsoft Visual Basic compiled application. In many cases, string constants remain in a linear, unencrypted form that debug/editor utilities can display. The sample Visual Basic code below encrypts a string with the XOR operator using password security. You can also adapt this technique to other dialects of Basic or other languages. NOTE: This behavior is not exhibited when a Visual Basic 5.0 application is compiled using the native mode compiler.
MORE INFORMATIONSoftware tools for debugging and viewing binary code can easily find ASCII strings stored in compiled executable .EXE programs. If you want to hide or protect strings in .EXE programs, you can use techniques such as these:
Example of String Encryption Using Xor FunctionCalling the Encrypt routine below encrypts a string using a password. Calling the Encrypt routine a second time decrypts the encrypted string.
Xor: The Exclusive-OR OperatorThe exclusive-OR operator (Xor in the Basic language) performs a logical exclusion on two expressions. For example:
Result = expr1 Xor expr2A useful behavior of Xor is that the first expression expr1 is returned without losing any bits when you perform Result Xor expr2. This ability to restore the first expression from the Result combined with the second expression is why the Xor function is useful for encryption. The Xor operator performs a bit-wise comparison of identically positioned bits in two numeric expressions and sets the corresponding bit in the result according to the following truth table:
If bit in expr1 is: And bit in expr2 is: The result is: --------------------------------------------------------------- 0 0 0 0 1 1 1 0 1 1 1 0 ASCII and ANSI Character SetsFor a listing of the ASCII and ANSI character sets, see the Help menu in Visual Basic. American Standard Code for Information Interchange (ASCII) is the 7-bit character set widely used to represent letters and symbols found on a standard United States keyboard. The ASCII character set is the same as the first 128 characters (0 to 127) in the American National Standards Institute (ANSI) character set. The ANSI character set uses all 8 bits in a byte, and includes 256 characters (0 to 255). ANSI characters 128 to 255 are sometimes referred to as the extended-ASCII characters.
REFERENCESThe following company offers encryption software and other products for Basic: Crescent Division, Progress Software, Inc. 14 Oak Park Bedford, MA 01730 USA Contact: Sales Information (800)352-2742, or Adam Schwartz (617)280-3000Fax: (617) 280-4025 Internet Web Site http://www.crescent.progress.com Ask about the QuickPak Professional Library for Windows. Products from Progress Software are manufactured independent of Microsoft. Microsoft makes no warranty, implied or otherwise, regarding these products' performance or reliability. |
Keywords : kb3rdparty kbcode PrgOther vb4all vb4win vb5all vb5howto vbwin kbfasttip kbhowto
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |