Mega Code Archive

 
Categories / C# Tutorial / Security
 

Asymmetric cryptography

using System; using System.IO; using System.Security.Cryptography; class MainClass {   public static void Main()    {     RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();     Byte[] testData = {1, 2, 3, 4, 5, 6, 7, 8};     Byte[] encryptedData = rsa.Encrypt(testData, false);     Console.WriteLine("Encrypted data:");     for(int i=0; i<encryptedData.GetLength(0); i++)     {       Console.Write("{0} ", encryptedData[i]);     }     Byte[] decryptedData = rsa.Decrypt(encryptedData, false);     Console.WriteLine("Decrypted Data:");     for(int i=0; i<decryptedData.GetLength(0); i++)     {       Console.Write("{0} ", decryptedData[i]);     }   } } Encrypted data: 105 216 155 138 34 149 122 27 220 172 6 69 23 21 224 142 30 166 81 141 15 234 144 235 122 187 99 245 222 252 154 234 211 79 251 80 253 221 94 91 222 86 225 17 0 96 161 179 155 251 123 140 38 6 161 78 111 193 19 222 251 74 172 104 100 61 39 106 113 67 69 45 237 47 194 189 62 168 98 230 196 149 249 11 3 29 19 66 10 84 73 110 142 142 255 120 138 200 207 79 190 151 164 53 4 198 254 78 203 86 102 233 10 7 216 13 41 166 125 155 58 48 214 27 116 93 211 176 191 183 Decrypted Data: 1 2 3 4 5 6 7 8