当前位置: 首页>>代码示例>>C#>>正文


C# RSACryptoServiceProvider.Decrypt方法代码示例

本文整理汇总了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);
        }
    }
}
开发者ID:.NET开发者,项目名称:System.Security.Cryptography,代码行数:51,代码来源:RSACryptoServiceProvider.Decrypt

示例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();
    }

}
开发者ID:C#程序员,项目名称:System.Security.Cryptography,代码行数:37,代码来源:RSACryptoServiceProvider.Decrypt


注:本文中的System.Security.Cryptography.RSACryptoServiceProvider.Decrypt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。