这是一个MSDN上的一个实例,我简单改了一下,把明文固定了,但为什么每次加密的结果都不一致,是不是还有一个设置没有完成,请高手指点!!!using System;
using System.Security.Cryptography;
class Class1
{
static void Main()
{
//initialze the byte arrays to the public key information.
byte[] PublicKey = {214,46,220,83,160,73,40,39,201,155,19,202,3,11,191,178,56,
74,90,36,248,103,18,144,170,163,145,87,54,61,34,220,222,
207,137,149,173,14,92,120,206,222,158,28,40,24,30,16,175,
108,128,35,230,118,40,121,113,125,216,130,11,24,90,48,194,
240,105,44,76,34,57,249,228,125,80,38,9,136,29,117,207,139,
168,181,85,137,126,10,126,242,120,247,121,8,100,12,201,171,
38,226,193,180,190,117,177,87,143,242,213,11,44,180,113,93,
106,99,179,68,175,211,164,116,64,148,226,254,172,147};
byte[] Exponent = {1,0,1};
byte[] EncryptedKey;
byte[] MM = {1,2,3,4,5,6,7,8,9,0,1,2,3,4,5}; //Create a new instance of RSACryptoServiceProvider.
RSACryptoServiceProvider RSA = new RSACryptoServiceProvider(); //Create a new instance of RSAParameters.
RSAParameters RSAKeyInfo = new RSAParameters(); //Set RSAKeyInfo to the public key values.
RSAKeyInfo.Modulus = PublicKey;
RSAKeyInfo.Exponent = Exponent;
//Import key parameters into RSA.
RSA.ImportParameters(RSAKeyInfo); //Encrypt
EncryptedKey = RSA.Encrypt(MM, false);//EncryptedKey每次加密都不一致???
}
}
using System.Security.Cryptography;
class Class1
{
static void Main()
{
//initialze the byte arrays to the public key information.
byte[] PublicKey = {214,46,220,83,160,73,40,39,201,155,19,202,3,11,191,178,56,
74,90,36,248,103,18,144,170,163,145,87,54,61,34,220,222,
207,137,149,173,14,92,120,206,222,158,28,40,24,30,16,175,
108,128,35,230,118,40,121,113,125,216,130,11,24,90,48,194,
240,105,44,76,34,57,249,228,125,80,38,9,136,29,117,207,139,
168,181,85,137,126,10,126,242,120,247,121,8,100,12,201,171,
38,226,193,180,190,117,177,87,143,242,213,11,44,180,113,93,
106,99,179,68,175,211,164,116,64,148,226,254,172,147};
byte[] Exponent = {1,0,1};
byte[] EncryptedKey;
byte[] MM = {1,2,3,4,5,6,7,8,9,0,1,2,3,4,5}; //Create a new instance of RSACryptoServiceProvider.
RSACryptoServiceProvider RSA = new RSACryptoServiceProvider(); //Create a new instance of RSAParameters.
RSAParameters RSAKeyInfo = new RSAParameters(); //Set RSAKeyInfo to the public key values.
RSAKeyInfo.Modulus = PublicKey;
RSAKeyInfo.Exponent = Exponent;
//Import key parameters into RSA.
RSA.ImportParameters(RSAKeyInfo); //Encrypt
EncryptedKey = RSA.Encrypt(MM, false);//EncryptedKey每次加密都不一致???
}
}
解决方案 »
- 求按钮提交后失效10秒钟的.net(C#)后台的写法,非JS
- udp操作时断开网络导致系统故障
- windows form 里有没有保存文件的方法(c#)
- datagridview.rows.count的值为什么会多一个?
- 奇怪,这种情况下验证控件不起作用了????
- 请高手指点迷津:关于C#调用C++WINDOWS32的动态库的在输入输出参数为string 或StringBulder的时候导致系统很不稳定而且经常出错
- 如何用C#实现下面的示例~VB.NET里面的Len函数
- WINCE 5.0下,VS2005 C# PICTUREBOX(插入图片),上的LABEL控件背景如何透明
- 彻底晕了,跪求?
- 删除DATAGRID中一条记录,在自己建的数据库中行,在SQL SERVER 带的PUBS数据库中不行,为什么?(在线等待!)
- 怎样设置验证控件在用户输完一个数据后就立刻执行验证?
- .net 调用存储过程问题
这是因为net下每次都添加了一些随机数,其实这些随机数的生成也是遵循算法标准的,
更专业的说是随机填充算法,