Encrypt your data using an ASP encryption algorithm (2)

zhaozj2021-02-16  88

In the first part, discuss how to generate a key, the following will show how this key is used to encrypt and decrypt a string.

The following code is a function of which can simultaneously implement this function CRYPT.ASP file <% DIM G_KEY Const g_cryptthis = "now the time for all good men to come to the aid of their country." Const g_keylocation = "C: / key. TXT "g_key = mid (readkeyfromfile (g_keylocation), 1, len (g_cryptthis)) response.write"

Original String: "& g_cryptthis &"

"response.write"

key value: "& g_key & "

" response.write "

Encrypted Cyphertext:" & Encrypt (g_cryptthis) & "

" response.write "

decrypted cyphertext:" & decrypt (encrypt (g_cryptthis)) & "< P> "Function Encrypt (Strcryptthis) DIM STRCHAR, IKEYCHAR, ISTRINGCHAR, I for i = 1 to Len (strcryptthis) iKeychar = ASC (MID (G_Key, I, 1)) istringChar = ASC (MID (StrcryptTHIS, I, 1) ) '*** uncomment below to encrypt with addition,' iCryptChar = iStringChar iKeyChar iCryptChar = iKeyChar Xor iStringChar strEncrypted = strEncrypted & Chr (iCryptChar) next EnCrypt = strEncrypted End Function Function DeCrypt (strEncrypted) Dim strChar, iKeyChar, iStringChar, I For i = 1 to len (strencrypted) iKeychar = ( Asc (mid (g_Key, I, 1))) iStringChar = Asc (mid (strEncrypted, I, 1)) '*** uncomment below to decrypt with subtraction' iDeCryptChar = iStringChar - iKeyChar iDeCryptChar = iKeyChar Xor iStringChar strDecrypted = strDecrypted & Chr (iDeCryptChar) next DeCrypt = strDecrypted End Function Function ReadKeyFromFile (strFileName) Dim keyFile, fso, f set fso = Server.CreateObject ( "Scripting.FileSystemObject") set f = fso.GetFile (strFileName) set ts =

转载请注明原文地址:https://www.9cbs.com/read-13005.html

New Post(0)