ASP VBSCRIPT VBA RSA 公钥加密 私钥解密 私钥签名 公钥验签

<% 
'@title: Class_Crypt_Rsa
'@author: ekede.com
'@date: 2020-10-28
'@description: RSA 公钥加密->私钥解密 , 私钥签名->公钥验签
Class Class_Crypt_Rsa
		Private TAsc,objRsa
		Private PrivateKey_,PublicKey_
        '@PrivateKey: Your personal private key.  Keep this hidden. Need C# format.
		Public Property Get PrivateKey
			PrivateKey = PrivateKey_
		End Property
		Public Property Let PrivateKey(Value)
			PrivateKey_ = Value
			objRsa.FromXmlString (PrivateKey_)
            PublicKey_ = objRsa.ToXmlString(False)
		End Property
        '@PublicKey: Key for others to encrypt data with.
		Public Property Get PublicKey
			PublicKey = PublicKey_
		End Property
		Public Property Let PublicKey(Value)
			PublicKey_ = Value
			objRsa.FromXmlString (PublicKey_)
		End Property
		Private Sub Class_Initialize()
			Set TAsc = Server.CreateObject("System.Text.UTF8Encoding")
			Set objRsa = Server.CreateObject("System.Security.Cryptography.RSACryptoServiceProvider")
			CreateKey()
		End Sub
		Private Sub Class_Terminate()
			Set objRsa = Nothing
			Set TAsc = Nothing
		End Sub
		Public Sub CreateKey()
			PrivateKey_ = objRsa.ToXmlString(True)
			PublicKey_ = objRsa.ToXmlString(False)
		End Sub
		'@Encrypt(ByRef Str): 公钥加密
		Public Function Encrypt(ByRef Str)
			Dim Bytes
			Bytes = TAsc.GetBytes_4(Str)
			Encrypt = Bytes2Base64(RsaEncrypt((Bytes)))
		End Function
		Private Function RsaEncrypt(ByRef Bytes)
			RsaEncrypt = objRsa.Encrypt((Bytes),False)
		End Function
		'@Decrypt(ByRef Bytes): 私钥解密
		Public Function Decrypt(ByRef Str)
			Dim Bytes
			Bytes=RsaDecrypt(Base642Bytes(Str))
			Decrypt = TAsc.GetString((Bytes))
		End Function
		Private Function RsaDecrypt(ByRef Bytes)
			 RsaDecrypt = objRsa.
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值