日期:2014-05-17  浏览次数:21094 次

.NET里的RSA类RSACryptoServiceProvider怎么与ASP的RSA类兼容?
ASP的RSA类是从网下Down的,代码如下:
1、test.asp
<%
rem 文章标题:在asp中通过vbs类实现rsa加密与解密

%>
<%Option Explicit%>
<!--#INCLUDE FILE="clsRSA.asp"-->
<%

Dim LngKeyE
Dim LngKeyD
Dim LngKeyN
Dim StrMessage
Dim ObjRSA
If Not Request.Form = "" Then

LngKeyE = Request.Form("KeyE")
LngKeyD = Request.Form("KeyD")
LngKeyN = Request.Form("KeyN")
StrMessage = Request.Form("Message")

Set ObjRSA = New clsRSA

Select Case Request.Form("Action")
Case "Generate Keys"
Call ObjRSA.GenKey()
LngKeyE = ObjRSA.PublicKey
LngKeyD = ObjRSA.PrivateKey
LngKeyN = ObjRSA.Modulus
Case "Encrypt"
ObjRSA.PublicKey = LngKeyE
ObjRSA.Modulus = LngKeyN
StrMessage = ObjRSA.Encode(StrMessage)
Case "Decrypt"
ObjRSA.PrivateKey = LngKeyD
ObjRSA.Modulus = LngKeyN
StrMessage = ObjRSA.Decode(StrMessage)
End Select

Set ObjRSA = Nothing

End If
%>
<HTML>
<HEAD>
<TITLE>RSA Cipher Demonstration</TITLE>
</HEAD>
<BODY>
<H1>RSA Cipher Demonstration</H1>
<P>
You will first need to generate your public/privage key-pair
before you can encrypt/decrypt messages.
</P>
<FORM method="post">
<TABLE>
<TR>
<TD>Public Key</TD>
<TD><INPUT name="KeyE" value="<%=Server.HTMLEncode(LngKeyE)%>"></TD>
<TD rowspan="3">
<INPUT type="Submit" name="Action" value="Generate Keys">
</TD>
</TR>
<TR>
<TD>Private Key</TD>
<TD><INPUT name="KeyD" value="<%=Server.HTMLEncode(LngKeyD)%>"></TD>
</TR>
<TR>
<TD>Modulus</TD>
<TD><INPUT name="KeyN" value="<%=Server.HTMLEncode(LngKeyN)%>"></TD>
</TR>
<TR>
<TD colspan="3">
Test Message:<BR>
<TEXTAREA name="Message" cols="50" rows="7"><%=Server.HTMLEncode(StrMessage)%></TEXTAREA>
</TD>
</TR>
<TR>
<TD align="right" colspan="3">
<INPUT type="Submit" name="Action" value="Encrypt">
<INPUT type="Submit" name="Action" value="Decrypt">
</TD>
</TR>
</TABLE>
</FORM>
</BODY>
</HTML> 

2、clsRSA.asp
<%
rem 实现rsa加密与解密的vbs类文件
rem 文章标题:在asp中通过vbs类实现rsa加密与解密

' RSA Encryption Class
'
' .PrivateKey
' Your personal private key. Keep this hidden.
'
' .PublicKey
' Key for others to encrypt data with.
'
' .Modulus
' Used with both public and private keys when encrypting
' and decrypting data.
'
' .GenKey()
' Creates Public/Private key set and Modulus
'
' .Crypt(pLngMessage, pLngKey) 
' Encrypts/Decrypts message and returns 
' as a string.
'
' .Encode(pStrMessage)
' Encrypts message and returns in double-hex format
'
' .Decode(pStrMessage)
' Decrypts message from double-hex format and returns a string
'
Class clsRSA

Public PrivateKey
Public PublicKey
Public Modulus

Public Sub GenKey()
Dim lLngPhi
Dim q
Dim p

Randomize

Do
Do

' 2 random primary numbers (0 to 1000)
Do
p = Rnd * 1000 \