PublicKey Cryptography : Encryption « 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 » Encryption 
35.14.2.PublicKey Cryptography
using System;
using System.Security.Cryptography;

  class Class1
  {
    static void Main(string[] args)
    {
      string dataToSign = "this is a test.";
      byte[] data_Bytes = System.Text.Encoding.ASCII.GetBytesdataToSign );
      
      SHA1Managed sha1 = new SHA1Managed();
      byte[] hash_Bytes = sha1.ComputeHashdata_Bytes );
    
      DSACryptoServiceProvider dsa = new DSACryptoServiceProvider()
      DSASignatureFormatter sigFormatter = new DSASignatureFormatter(dsa);
      sigFormatter.SetHashAlgorithm("SHA1");
      byte[] signedHash = sigFormatter.CreateSignaturehash_Bytes );

      byte[] remote_SignedHash = signedHash;
      byte[] remote_HashedValue = hash_Bytes;

      DSASignatureDeformatter sigDeformatter = new DSASignatureDeformatterdsa );
      sigDeformatter.SetHashAlgorithm"SHA1" );

      Console.WriteLine(sigDeformatter.VerifySignatureremote_HashedValue, remote_SignedHash ));

      RSACryptoServiceProvider rsa=  new RSACryptoServiceProvider();
      byte[] dataToEncrypt = System.Text.Encoding.Unicode.GetBytes"Encrypt THIS!" );
      byte[] encrypted_Bytes;
      byte[] decrypted_Bytes;

      encrypted_Bytes = rsa.EncryptdataToEncrypt, false );
      Console.WriteLine("RSA-encrypted data is {0} bytes long.", encrypted_Bytes.Length);
      decrypted_Bytes = rsa.Decryptencrypted_Bytes, false );
      Console.WriteLine("RSA-decrypted string is {0}.", System.Text.Encoding.Unicode.GetStringdecrypted_Bytes ));
    }
  }
35.14.Encryption
35.14.1.Symmetric Encryption
35.14.2.PublicKey Cryptography
35.14.3.Secret Key Cryptography: RijndaelManaged
35.14.4.Create a new instance of the CipherData class using CipherReference information.
35.14.5.Use DataReference to encrypt and decrypt multiple XML elements using different session keys.
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.