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
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.