Encryption | data | Introduction to Algorithms
First, a brief introduction to the background of encryption. Because the United States prohibits several cryptographic algorithms from exporting encrypted digits (such as SSL's 40-bit encryption limit), this article describes a simple character encryption algorithm that an ASP can use, rather than a restricted encryption algorithm. In fact, the encryption algorithm introduced here for the general application is enough to decrypt people for a while. Its encryption base is the simplest Vernum password method, which I will introduce in my next article.
Its rationale is that there is a need to encrypt the
PlainText and a randomly generated decryption key file. The two files are then combined to generate the ciphertext.
(plaintext) combination (key) = encrypted ciphertext
So this article is about the code that generates the key. We assume that the key we generated is a 512-bit long key, which is enough to encrypt a text character. The code is as follows:
keygen.asp file
<%
'******************************
' Keygen.asp
'******************************
Const g_keylocation = "C:\key.txt"
Const G_keylen = 512
On Error Resume Next
Call Writekeytofile (KeyGeN (G_keylen), g_keylocation)
If ERR <> 0 Then
Response.Write "ERROR generating KEY." & "<P>"
Response.Write Err.Number & "<BR>"
Response.Write Err.Description & "<BR>"
Else
Response.Write "KEY successfully generated."
End If
Sub Writekeytofile (Mykeystring,strfilename)
Dim KeyFile, FSO
Set fso = Server.CreateObject ("Scripting.") FileSystemObject ")
Set keyfile = FSO. CreateTextFile (strFileName, True)
Keyfile.writeline (mykeystring)
Keyfile.close
End Sub
Function KeyGeN (ikeylength)
Dim K, icount, Strmykey
Lowerbound = 35
Upperbound = 96
Randomize ' Initialize random-number generator.
For I = 1 to Ikeylength
s = 255
K = Int (((upperbound-lowerbound) + 1) * Rnd + lowerbound)
Strmykey = Strmykey & Chr (k) & ""
Next
KeyGeN = Strmykey
End Function
%>
Run the above keygen.asp page under IIS. You just have to do this once, and he will write the key in the file C:\key.txt (you can also put the file in a more secure place if you want to). You can then open the Key.txt file, which will contain 512 ASCII characters between 35 and 96. And because it is randomly generated, everyone's private key file Key.txt will be different, and here is an example key file:
iy/;$>=3)? ^-+7m32#q]voii. Q=OFMC ':P 7_b;<r/8u) xfhc<sr_e$. DLG ' =i+@5%*+op:f_= '; ' Nsy '-^s. ' Aa=bj3m0. WF#T5LGK (=/<:+c2k/^7ai$; PU ' Ome2+t8nd? W$c (j\,;631 ' m-ld5f%%1tf_&k2a-d-54[2p,# ' *ju%6 ' 0rf3cmf0 (#T07U ' fz=>#,+. 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<oz6in?7n4<gtl? (M ' 4S8+3JMK5] Hc%^1^+k;\ $WBXPA? F&5^e\d$7%*o/u[1/?8 ( 5:1ovwv*1z-% ': K&v? X1,1KURD@3W0^D) <og40? (vj4ewl5a5m< $A); cq36r9i]*u#q%1<y\&sa% #1 <v
The following is a careful analysis of the above procedures, we found that the lowerbound and Upperbound values are actually the ASCII character range that you want to encrypt. The following article describes how to use this key to encrypt and decrypt a string