vb.net中实现rsa加密解密 急!急!

来源:百度知道 编辑:UC知道 时间:2024/05/15 18:13:32
在asp中实现rsa加密解密的代码中有:
NumberToHex = Right(string(pLngLength, "0") & Hex(pLngNumber), pLngLength)
但是在aspx(vb.NET)中不能使用string,请问要如何修改,才能在.net中使用?

我觉得你的并不是RSA加密解密算法。

在.net的有一个System.Security.Cryptography的命名空间,里面有一RSACryptoServiceProvider的类用来对byte进行RSA加密解密。

具体例子如下:
using System;
using System.Security.Cryptography;
using System.Text;

class RSACSPSample
{

static void Main()
{
try
{
//Create a UnicodeEncoder to convert between byte array and string.
UnicodeEncoding ByteConverter = new UnicodeEncoding();

//Create byte arrays to hold original, encrypted, and decrypted data.
byte[] dataToEncrypt = ByteConverter.GetBytes("Data to Encrypt");
byte[] encryptedData;
byte[] decryptedData;

//Create a new instance of RSACryptoServiceProvider to generate
//public and private key data.
RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();