Asymmetric cryptography : RSA « Security « C# / CSharp Tutorial

Home
C# / CSharp Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statement
5.String
6.struct
7.Class
8.Operator Overload
9.delegate
10.Attribute
11.Data Structure
12.Assembly
13.Date Time
14.Development
15.File Directory Stream
16.Preprocessing Directives
17.Regular Expression
18.Generic
19.Reflection
20.Thread
21.I18N Internationalization
22.LINQ
23.GUI Windows Forms
24.Windows Presentation Foundation
25.Windows Communication Foundation
26.Workflow
27.2D
28.Design Patterns
29.Windows
30.XML
31.XML LINQ
32.ADO.Net
33.Network
34.Directory Services
35.Security
36.unsafe
C# / C Sharp
C# / C Sharp by API
C# / CSharp Open Source
C# / CSharp Tutorial » Security » RSA 
35.10.1.Asymmetric cryptography
using System;
using System.IO;
using System.Security.Cryptography;

class MainClass
{
  public static void Main() 
  {
    RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();

    Byte[] testData = {12345678};

    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
35.10.RSA
35.10.1.Asymmetric cryptography
35.10.2.Encrypt with RSACryptoServiceProvider
35.10.3.Using RSACryptoServiceProvider
35.10.4.Using RSAPKCS1SignatureDeformatter
35.10.5.RSACryptoServiceProvider reads from xml key
35.10.6.CspParameters and RSACryptoServiceProvider
35.10.7.Encrypt an XML document using an asymmetric key
35.10.8.Use RSAPKCS1SignatureFormatter to create a digital signature and then uses the RSAPKCS1SignatureDeformatter class to verify the signature.
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.