解码OAEP填充时发生错误

时间:2009-06-04 11:13:10

标签: c# security encryption digital-signature rsacryptoserviceprovider

我解决了我的问题..请帮助..

我已使用数字签名的公钥成功加密了文本,但在解密时,我收到了错误。

解码OAEP填充时出错。

我的代码如下。

#region
Test Encryption 
public void a() 
{
using (var rsa = new RSACryptoServiceProvider()) 
{
// This String consists only Public Key Information 
String publicKeyOnly = rsa.ToXmlString(false); 
// This String consists both Private/Public Key information 
String publicPrivate = rsa.ToXmlString(true); 
}
}
//encrypt 
public byte[] b(String publicKeyOnly) 
{
byte[] encryptedData; 
using (var rsaPublicOnly = new RSACryptoServiceProvider()) 
{
rsaPublicOnly.FromXmlString(publicKeyOnly);
encryptedData = rsaPublicOnly.Encrypt(
Encoding.UTF8.GetBytes("This String is to be Secured."), true); 
}
return encryptedData; 
}
//Decrypt 
public String c( byte[] encryptedData) 
{
String decryptedPassword ; 
using (var rsaPublicPrivate = new RSACryptoServiceProvider()) 
{
RSACryptoServiceProvider.UseMachineKeyStore = true; 
// Providing Private key information to RSA Object 
rsaPublicPrivate.FromXmlString(_PrivateKeyXML);
// Decrypting the encrypted data by using RSA object "rsaPublicPrivate" 
decryptedPassword = rsaPublicPrivate.Decrypt(encryptedData,
true).ToString(); 
}
return decryptedPassword; 
}
#endregion

0 个答案:

没有答案