The correction method of encryption method in the ASP has a corresponding decryption method, and now it is now organized in the ASP encryption and decryption function according to the seniors.
RSA.asp
<%
Rem Enables encryption and decryption in ASP, encryption method: According to RSA
REM Contact: hnsoso@sina.com
Class CLSRSA
Public PrivateKey
Public Publickey, PUBLIC
Public MODULUS
Public Function Crypt (PLNGMESSAGE, PLNGKEY)
ON Error ResMe 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 ResMe 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
<%
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 "Encryption:" & first
Last = encryptstr (first)
Response.write "Encryption" & LAST
Response.write "Decoupted" & DecryptStr (Last)
%>