CSharpTest.Net
RSAPublicKey Class
Members  Example  See Also  Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Crypto Namespace : RSAPublicKey Class

Glossary Item Box

Provides a wrapper around encrypting with public keys from Certificats or CSP

Syntax

Visual Basic (Declaration) 
Public Class RSAPublicKey 
   Inherits AsymmetricKey
   Implements IEncryptDecrypt 
C# 
public class RSAPublicKey : AsymmetricKey, IEncryptDecrypt  

Example

Library/Library.Test/TestRSACrypto.cs

C#Copy Code
byte[] rawdata = new byte[8001];
new Random().NextBytes(rawdata);

byte[] cypher;
using (RSAPublicKey publicKey = new RSAPublicKey(TestCertPublicKey()))
    cypher = publicKey.Encrypt(rawdata);

using (RSAPrivateKey privateKey = new RSAPrivateKey(TestCertPrivateKey()))
    Assert.AreEqual(rawdata, privateKey.Decrypt(cypher));
VB.NETCopy Code
Dim rawdata As Byte() = New Byte(8001) {}
New Random().NextBytes(rawdata)

Dim cypher As Byte()
Using publicKey As New RSAPublicKey(TestCertPublicKey())
    cypher = publicKey.Encrypt(rawdata)
End Using

Using privateKey As New RSAPrivateKey(TestCertPrivateKey())
    Assert.AreEqual(rawdata, privateKey.Decrypt(cypher))
End Using

Inheritance Hierarchy

System.Object
   CSharpTest.Net.Crypto.CryptoKey
      CSharpTest.Net.Crypto.AsymmetricKey
         CSharpTest.Net.Crypto.RSAPublicKey
            CSharpTest.Net.Crypto.RSAPrivateKey

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys