Encryption | Decryption in the ASP encryption method has a corresponding decryption method does not seem much, now based on the predecessors of the data in the ASP encryption and decryption function
Rsa.asp
<%
REM Encryption and decryption in ASP, encryption method: according to RSA
REM Contact: hnsoso@sina.com
Class Clsrsa
Public Privatekey
Public PublicKey
Public modulus
Public Function Crypt (Plngmessage, Plngkey)
On Error Resume Next
Dim Llngmod
Dim Llngresult
Dim Llngindex
If plngkey Mod 2 = 0 Then
Llngresult = 1
For llngindex = 1 to PLNGKEY/2
Llngmod = (plngmessage ^ 2) Mod modulus
' Mod may error on key generation
Llngresult = (Llngmod * llngresult) Mod modulus
If Err Then Exit Function
Next
Else
Llngresult = Plngmessage
For llngindex = 1 to PLNGKEY/2
Llngmod = (plngmessage ^ 2) Mod modulus
On Error Resume Next
' Mod may error on key generation
Llngresult = (Llngmod * llngresult) Mod modulus
If Err Then Exit Function
Next
End If
Crypt = Llngresult
End Function
Public Function Encode (ByVal pstrmessage)
Dim Llngindex
Dim Llngmaxindex
Dim Lbytascii
Dim llngencrypted
Llngmaxindex = Len (pstrmessage)
If llngmaxindex = 0 Then Exit Function
For llngindex = 1 to Llngmaxindex
Lbytascii = ASC (Mid (Pstrmessage, Llngindex, 1))
llngencrypted = Crypt (Lbytascii, PublicKey)
Encode = Encode & Numbertohex (llngencrypted, 4)
Next
End Function
Public Function Decode (ByVal pstrmessage)
Dim Lbytascii
Dim Llngindex
Dim Llngmaxindex
Dim Llngencrypteddata
Decode = ""
Llngmaxindex = Len (pstrmessage)
For llngindex = 1 to Llngmaxindex step 4
Llngencrypteddata = Hextonumber (Mid (Pstrmessage, Llngindex, 4))
Lbytascii = Crypt (Llngencrypteddata, Privatekey)
Decode = Decode & Chr (LBYTASCII)
Next
End Function
Private Function Numbertohex (ByRef plngnumber, ByRef plnglength)
Numbertohex = Right (String (Plnglength, "0") & Hex (Plngnumber), plnglength)
End Function
Private Function hextonumber (ByRef pstrhex)
Hextonumber = CLng ("&h" & Pstrhex)
End Function
End Class
%>
Test.asp
<!--#INCLUDE file= "rsa.asp"-->
<%
function encryptstr (message)
Dim Lngkeye
Dim Lngkeyd
Dim Lngkeyn
Dim strmessage
Dim Objrsa
Lngkeye = "32823"
Lngkeyd = "20643"
Lngkeyn = "29893"
strmessage = Message
Set Objrsa = New Clsrsa
Objrsa.publickey = Lngkeye
Objrsa.modulus = Lngkeyn
Encryptstr = Objrsa.encode (strmessage)
Set Objrsa = Nothing
End Function
function decryptstr (message)
Dim Lngkeye
Dim Lngkeyd
Dim Lngkeyn
Dim strmessage
Dim Objrsa
Lngkeye = "32823"
Lngkeyd = "20643"
Lngkeyn = "29893"
strmessage = Message
Set Objrsa = New Clsrsa
Objrsa.privatekey =lngkeyd
Objrsa.modulus=lngkeyn
Decryptstr=objrsa.decode (strmessage)
Set Objrsa = Nothing
End Function
Dim Last,first
First= "Sohu"
Response.Write "Before encrypting:" &first
Last=encryptstr (a)
Response.Write "After Encryption" &last
Response.Write "Decrypted as" &decryptstr (last)
%>