Visual Basic (Declaration) | |
---|---|
Public Class RSAPrivateKey Inherits RSAPublicKey Implements IEncryptDecrypt |
C# | |
---|---|
public class RSAPrivateKey : RSAPublicKey, IEncryptDecrypt |
Library/Library.Test/TestRSACrypto.cs
C# | Copy Code |
---|---|
byte[] data = new byte[100]; new Random().NextBytes(data); foreach (HashAlgorithm ha in new HashAlgorithm[] { MD5.Create(), SHA1.Create(), SHA256.Create(), SHA384.Create(), SHA512.Create() }) { Hash hash = Hash.FromBytes(ha.ComputeHash(data)); Assert.AreEqual(CryptoConfig.MapNameToOID(ha.GetType().FullName), hash.AlgorithmOID); using (RSAPrivateKey key = new RSAPrivateKey()) { byte[] sig = key.SignHash(hash); using (RSAPublicKey pub = key.PublicKey) { Assert.IsTrue(pub.VerifyHash(sig, Hash.FromBytes(ha.ComputeHash(data)))); data[0] = (byte)~data[0]; Assert.IsFalse(pub.VerifyHash(sig, Hash.FromBytes(ha.ComputeHash(data)))); } } } |
VB.NET | Copy Code |
---|---|
Dim data As Byte() = New Byte(100) {} New Random().NextBytes(data) For Each ha As HashAlgorithm In New HashAlgorithm() {MD5.Create(), SHA1.Create(), SHA256.Create(), SHA384.Create(), SHA512.Create()} Dim hash As Hash = Hash.FromBytes(ha.ComputeHash(data)) Assert.AreEqual(CryptoConfig.MapNameToOID(ha.[GetType]().FullName), hash.AlgorithmOID) Using key As New RSAPrivateKey() Dim sig As Byte() = key.SignHash(hash) Using pub As RSAPublicKey = key.PublicKey Assert.IsTrue(pub.VerifyHash(sig, Hash.FromBytes(ha.ComputeHash(data)))) data(0) = DirectCast(Not data(0), Byte) Assert.IsFalse(pub.VerifyHash(sig, Hash.FromBytes(ha.ComputeHash(data)))) End Using End Using Next |
System.Object
CSharpTest.Net.Crypto.CryptoKey
CSharpTest.Net.Crypto.AsymmetricKey
CSharpTest.Net.Crypto.RSAPublicKey
CSharpTest.Net.Crypto.RSAPrivateKey
Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7
Reference
RSAPrivateKey MembersCSharpTest.Net.Crypto Namespace
Source Code
Library/Crypto/RSAPrivateKey.csUsed By
RSAPrivateKey RSAPrivateKey.FromParameters(RSAParameters)RSAPrivateKey RSAPrivateKey.FromBytes(Byte[])
RSAPrivateKey RSAPrivateKey.FromStore(String)
RSAPrivateKey RSAPrivateKey.FromStore(CspParameters)