有密钥、已经加密的数据、能不能得到解密算法
本帖最后由 ansha2008 于 2012-12-28 16:10:56 编辑
现在客户给出了公钥、私钥、图书密钥、加密的图书数据,提供了参考的RSA算法,让我做个RSA解密算法,去解密图书,请问一下能不能做出来?如何做?
------解决方案--------------------提供以下作为参考,既然已经有了公钥和私钥那么就不必随机生成并返回密钥直接将密钥替换掉原来的密钥变量即可。
答题思路就是:new 一个rsa对象,填充密钥进行解密。
class RSACSPSample
{
static void jiami()
{
try
{
string str_Plain_Text = "我是初学者";
Console.WriteLine("明文:" + str_Plain_Text);
Console.WriteLine("长度:" + str_Plain_Text.Length.ToString());
Console.WriteLine();
RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
string str_Public_Key;
string str_Private_Key;
string str_Cypher_Text = RSA_Encrypt(str_Plain_Text, out str_Public_Key,out str_Private_Key);
Console.WriteLine("密文:" + str_Cypher_Text);
Console.WriteLine("公钥:" + str_Public_Key);
Console.WriteLine("私钥:" + str_Private_Key);
string str_Plain_Text2 = RSA_Decrypt(str_Cypher_Text, str_Private_Key);
Console.WriteLine("解密:" + str_Plain_Text2);
Console.WriteLine();
}
catch (ArgumentNullException)
{
Console.WriteLine("Encryption failed.");
}
}
//RSA加密,随机生成公私钥对并作为出参返回
static public string RSA_Encrypt(string str_Plain_Text, out string str_Public_Key, out string str_Private_Key)
{
str_Public_Key = "";
str_Private_Key = "";
UnicodeEncoding ByteConverter = new UnicodeEncoding();
byte[] DataToEncrypt = ByteConverter.GetBytes(str_Plain_Text);
try
{
RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
str_Public_Key = Convert.ToBase64String(RSA.ExportCspBlob(false));