Encrypt your data using the ASP encryption algorithm

xiaoxiao2021-03-06  41

Encrypt your data using the ASP encryption algorithm (1)

The introduction first briefly introduces the background about the encryption. Due to the US prohibiting several cryptographic algorithms (eg, 40-bit encryption restrictions on SSL), this article will introduce an ASP that can be used in the simple character encryption algorithm, not those limited. In fact, the encryption algorithm introduced here is enough to decrypt people for a while for the general purpose. Its encryption basis is the simplest Vernum password method, I will introduce this password in the next article. Its basic principle is that there is a need to have a plain text that needs to be encrypted and a randomly generated decryption key file. Then use these two files to generate ciphertext. (Plaintext) combination (key) = encrypted ciphertext So this article describes the code that generates a key. We assume that we have a key to 512-bit keys, which is enough to encrypt a text character. The code is as follows: Keygen.asp file <% '******************************************* ************************* CONST G_KEYLOCATION = "c: /key.txt" const g_keylen = 512

ON Error ResMe next

Call writekeyTofile (Keygen (g_keylen), g_keylocation

IF Err <> 0 ThenRESPONSE.WRITE "Error Generating Key." & "

" response.write err.number & "" response.write err.description & "" elseresponse.write "key successful generated." Endix

Sub WriteKeyToFile (MyKeyString, strFileName) Dim keyFile, fsoset fso = Server.CreateObject ( "scripting.FileSystemObject") set keyFile = fso.CreateTextFile (strFileName, true) keyFile.WriteLine (MyKeyString) keyFile.CloseEnd Sub

Function KeyGeN (iKeyLength) Dim k, iCount, strMyKeylowerbound = 35 upperbound = 96Randomize 'Initialize random-number generator.for I = 1 to iKeyLengths = 255k = Int (((upperbound - lowerbound) 1) * Rnd lowerbound) strMyKey = StrmyKey & Chr (K) & "NextKeygen = StrmyKeyend Function

%> Run the top of the key .asp page in IIS. You only need this to do this, he will write the key in the file C: /key.txt (if you like, you can also put this file in another more secure place). Then you can open this key .txt file, it will contain 512 ASCII code characters between 35 to 96. And because it is randomly generated, the private key files of each person will be different, the following is an example key File: ^ - 7M32 # q] Voii.Q = OFMC`: p7_b; #, . AW _ / '] DIB; 2DTIA57TT & -) O '/ * F'M> H.XH5W ^ 0y * = 71 5 * ^ `^ PKJ (= E / X # 7A:?, S> R & T; B # <: - * / @) x9f`_`% qa3z95.? _ T # 1, $ 2 # fww5pbh ^ * <]) A (S0 @ AVD8C ^ Q0R ^ T1D? (1 , Ye71X . * U $: 3xo ^ Q] .kg & 0N0]; [LJ

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 be implemented at the same time CRYPT.ASP file <% DIM G_KEY

Const g_cryptthis = "Now is the time for all good men to come to the aid of their country." Const g_keylocation = "c: /key.txt"

g_key = mid (readkeyfromfile, 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)) & "

" Function EnCrypt (strCryptThis) Dim strChar, iKeyChar, iStringChar, Ifor 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 iKeyChariCryptChar = Ikeychar xor istringcharstrencrypted = streencrypted & chr (icryptchar) Nextencrypt = strencryptedend function

Function decrypt (strencrypted) Dim strchar, iKeychar, istringchar, Ifor 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 iStringCharstrDecrypted = strDecrypted & Chr (iDeCryptChar) nextDeCrypt = strDecryptedEnd Function

Function ReadKeyFromFile (strFileName) Dim keyFile, fso, fset fso = Server.CreateObject ( "Scripting.FileSystemObject") set f = fso.GetFile (strFileName) set ts = f.OpenAsTextStream (1, -2)

Do while not ts.atendofstreamkeyfile = keyfile & ts.readLineloop

ReadkeyFromFile = KeyFileEnd Function

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

New Post(0)