本文整理汇总了C#中System.Security.Cryptography.RSACryptoServiceProvider.Decrypt方法的典型用法代码示例。如果您正苦于以下问题:C# RSACryptoServiceProvider.Decrypt方法的具体用法?C# RSACryptoServiceProvider.Decrypt怎么用?C# RSACryptoServiceProvider.Decrypt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.Cryptography.RSACryptoServiceProvider
的用法示例。
在下文中一共展示了RSACryptoServiceProvider.Decrypt方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//引入命名空间
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.
ASCIIEncoding ByteConverter = new ASCIIEncoding();
string dataString = "Data to Encrypt";
//Create byte arrays to hold original, encrypted, and decrypted data.
byte[] dataToEncrypt = ByteConverter.GetBytes(dataString);
byte[] encryptedData;
byte[] decryptedData;
//Create a new instance of the RSACryptoServiceProvider class
// and automatically create a new key-pair.
RSACryptoServiceProvider RSAalg = new RSACryptoServiceProvider();
//Display the origianl data to the console.
Console.WriteLine("Original Data: {0}", dataString);
//Encrypt the byte array and specify no OAEP padding.
//OAEP padding is only available on Microsoft Windows XP or
//later.
encryptedData = RSAalg.Encrypt(dataToEncrypt, false);
//Display the encrypted data to the console.
Console.WriteLine("Encrypted Data: {0}", ByteConverter.GetString(encryptedData));
//Pass the data to ENCRYPT and boolean flag specifying
//no OAEP padding.
decryptedData = RSAalg.Decrypt(encryptedData, false);
//Display the decrypted plaintext to the console.
Console.WriteLine("Decrypted plaintext: {0}", ByteConverter.GetString(decryptedData));
}
catch(CryptographicException e)
{
//Catch this exception in case the encryption did
//not succeed.
Console.WriteLine(e.Message);
}
}
}
示例2: Main
//引入命名空间
using System;
using System.IO;
using System.Security.Cryptography;
public class Example19_11
{
public static void Main()
{
// Create a new crypto provider
RSACryptoServiceProvider rsa =
new RSACryptoServiceProvider();
// Data to encrypt
Byte[] testData = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
// Encrypt the data
Byte[] encryptedData = rsa.Encrypt(testData, false);
Console.WriteLine("Encrypted data:");
for(int i=0; i<encryptedData.GetLength(0); i++)
{
Console.Write("{0} ", encryptedData[i]);
}
Console.WriteLine();
// Decrypt the data
Byte[] decryptedData = rsa.Decrypt(encryptedData, false);
Console.WriteLine("Decrypted Data:");
for(int i=0; i<decryptedData.GetLength(0); i++)
{
Console.Write("{0} ", decryptedData[i]);
}
Console.WriteLine();
}
}