在asp中通过vbs类实现rsa加密与解密

2016-01-29 20:24 100 1 收藏

在asp中通过vbs类实现rsa加密与解密,在asp中通过vbs类实现rsa加密与解密

【 tulaoshi.com - ASP 】

本文章有两文件组成
test.asp 测试演示文件
clsrsa.asp 实现rsa加密与解密的vbs类文件
下面是代码:

1. test.asp

(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/asp/)

<%
rem 文章标题:在asp中通过vbs类实现rsa加密与解密
rem 收集整理:yanek
rem 联系:aspboy@263.net

(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/asp/)

%
<%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
<TITLERSA Cipher Demonstration</TITLE
</HEAD
<BODY
<H1RSA 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
<TDPublic 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
<TDPrivate Key</TD
<TD<INPUT name="KeyD" value="<%=Server.HTMLEncode(LngKeyD)%"</TD
</TR
<TR
<TDModulus</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

clsrsa.asp

<%
rem 实现rsa加密与解密的vbs类文件
rem 文章标题:在asp中通过vbs类实现rsa加密与解密
rem 收集整理:yanek
rem 联系:aspboy@263.net

' 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 1
Loop While Not IsPrime(p)

Do
q = Rnd * 1000 1
Loop While Not IsPrime(q)


' n = product of 2 primes
Modulus = p * q 1

' random decryptor (2 to n)
PrivateKey = Rnd * (Modulus - 2) 1 + 2

lLngPhi = (p - 1) * (q - 1) 1
PublicKey = Euler(lLngPhi, PrivateKey)

Loop While PublicKey = 0 Or PublicKey = 1

' Loop if we can't crypt/decrypt a byte
Loop While Not TestCrypt(255)

End Sub

Private Function TestCrypt(ByRef pBytData)
Dim lStrCrypted
lStrCrypte

来源:http://www.tulaoshi.com/n/20160129/1511111.html

延伸阅读
标签: Web开发
为了讲解方便,突出重点,本文用数组实现要显示的商品信息。但在实际的系统开发中,这些商品信息的数据应该来自后台数据库。 在程序中,我们定义了一个sp数组并对其赋值,然后用一个循环实现其数据显示及对下一个程序的数据传递。程序部分代码如下: <% i=1 do while (i<=5) %> <tr > <td><%=sp(i)%></td> <td><a h...
标签: ASP
<!--#include file="token.asp"-- <% ' ************************************************************************* ' This is all test/example code showing the calling syntax of the ' cBuffer class ... the interface to the cBuffer object is quite simple. ' ' Use it for reference ... delete it ... whatever. ' ********...
标签: ASP
       <% Class cBuffer   Private objFSO, objFile, objDict   Private m_strPathToFile, m_TableBGColor, m_StartTime   Private m_EndTime, m_LineCount, m_intKeyMin, m_intKeyMax   Private m_CodeColor, m_CommentColor, m_StringColor, m_TabSpaces &n...
代码如下: using System; using System.Security.Cryptography; using System.Text; using System.IO; namespace Common ...{     /**//// summary     /// DESEncrypt加密解密算法。     /// /summary     public sealed class DESEncrypt     ...{  &nb...
using System; using System.IO; using System.Security.Cryptography; namespace Vavic { /// /// Security 的摘要说明。 /// public class Security { const string KEY_64 = "VavicApp"; const string IV_64 = "VavicApp"; //注意了,是8个字符,64位 public Security() { // // TODO: 在此处添加构造函数逻辑 // } publ...

经验教程

313

收藏

100
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部