C# Class System.Security.Cryptography.RSACryptoServiceProvider

Inheritance: RSA, ICspAsymmetricAlgorithm
Exibir arquivo Open project: dotnet/corefx Class Usage Examples

Private Properties

Property Type Description
AcquireSafeProviderHandle System.Security.Cryptography.SafeProvHandle
GetAlgorithmId int
GetHashAlgorithm HashAlgorithm
HashAlgorithmNameNullOrEmpty Exception
IsPublic bool
IsPublic bool
PaddingModeNotSupported Exception
RSACryptoServiceProvider System.Diagnostics
SignHash byte[]
VerifyHash bool

Public Methods

Method Description
Decrypt ( byte data, RSAEncryptionPadding padding ) : byte[]
Decrypt ( byte rgb, bool fOAEP ) : byte[]

Decrypt raw data, generally used for decrypting symmetric key material

Encrypt ( byte data, RSAEncryptionPadding padding ) : byte[]
Encrypt ( byte rgb, bool fOAEP ) : byte[]

Encrypt raw data, generally used for encrypting symmetric key material.

This method can only encrypt (keySize - 88 bits) of data, so should not be used for encrypting arbitrary byte arrays. Instead, encrypt a symmetric key with this method, and use the symmetric key to encrypt the sensitive data.

ExportCspBlob ( bool includePrivateParameters ) : byte[]

Exports a blob containing the key information associated with an RSACryptoServiceProvider object.

ExportParameters ( bool includePrivateParameters ) : RSAParameters

Exports the RSAParameters

ImportCspBlob ( byte keyBlob ) : void

Imports a blob that represents RSA key information

ImportParameters ( RSAParameters parameters ) : void

Imports the specified RSAParameters

RSACryptoServiceProvider ( ) : System.Diagnostics
RSACryptoServiceProvider ( CspParameters parameters ) : System.Diagnostics
RSACryptoServiceProvider ( int dwKeySize ) : System.Diagnostics
RSACryptoServiceProvider ( int dwKeySize, CspParameters parameters ) : System.Diagnostics
SignData ( Stream inputStream, Object halg ) : byte[]

Computes the hash value of a subset of the specified byte array using the specified hash algorithm, and signs the resulting hash value.

SignData ( byte buffer, Object halg ) : byte[]

Computes the hash value of a subset of the specified byte array using the specified hash algorithm, and signs the resulting hash value.

SignData ( byte buffer, int offset, int count, object halg ) : byte[]

Computes the hash value of a subset of the specified byte array using the specified hash algorithm, and signs the resulting hash value.

SignHash ( byte hash, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding ) : byte[]
SignHash ( byte rgbHash, string str ) : byte[]

Computes the hash value of a subset of the specified byte array using the specified hash algorithm, and signs the resulting hash value.

VerifyData ( byte buffer, object halg, byte signature ) : bool

Verifies the signature of a hash value.

VerifyHash ( byte hash, byte signature, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding ) : bool
VerifyHash ( byte rgbHash, string str, byte rgbSignature ) : bool

Verifies the signature of a hash value.

Protected Methods

Method Description
Dispose ( bool disposing ) : void

Dispose the key handles

HashData ( Stream data, HashAlgorithmName hashAlgorithm ) : byte[]
HashData ( byte data, int offset, int count, HashAlgorithmName hashAlgorithm ) : byte[]

Private Methods

Method Description
AcquireSafeProviderHandle ( ) : System.Security.Cryptography.SafeProvHandle

This method helps Acquire the default CSP and avoids the need for static SafeProvHandle in CapiHelper class

GetAlgorithmId ( HashAlgorithmName hashAlgorithm ) : int
GetHashAlgorithm ( HashAlgorithmName hashAlgorithm ) : HashAlgorithm
HashAlgorithmNameNullOrEmpty ( ) : Exception
IsPublic ( RSAParameters rsaParams ) : bool

Since P is required, we will assume its presence is synonymous to a private key.

IsPublic ( byte keyBlob ) : bool

find whether an RSA key blob is public.

PaddingModeNotSupported ( ) : Exception
RSACryptoServiceProvider ( int keySize, CspParameters parameters, bool useDefaultKeySize ) : System.Diagnostics
SignHash ( byte rgbHash, int calgHash ) : byte[]

Computes the hash value of a subset of the specified byte array using the specified hash algorithm, and signs the resulting hash value.

VerifyHash ( byte rgbHash, int calgHash, byte rgbSignature ) : bool

Verifies the signature of a hash value.

Method Details

Decrypt() public method

public Decrypt ( byte data, RSAEncryptionPadding padding ) : byte[]
data byte
padding RSAEncryptionPadding
return byte[]

Decrypt() public method

Decrypt raw data, generally used for decrypting symmetric key material
public Decrypt ( byte rgb, bool fOAEP ) : byte[]
rgb byte encrypted data
fOAEP bool true to use OAEP padding (PKCS #1 v2), false to use PKCS #1 type 2 padding
return byte[]

Dispose() protected method

Dispose the key handles
protected Dispose ( bool disposing ) : void
disposing bool
return void

Encrypt() public method

public Encrypt ( byte data, RSAEncryptionPadding padding ) : byte[]
data byte
padding RSAEncryptionPadding
return byte[]

Encrypt() public method

Encrypt raw data, generally used for encrypting symmetric key material.
This method can only encrypt (keySize - 88 bits) of data, so should not be used for encrypting arbitrary byte arrays. Instead, encrypt a symmetric key with this method, and use the symmetric key to encrypt the sensitive data.
public Encrypt ( byte rgb, bool fOAEP ) : byte[]
rgb byte raw data to encrypt
fOAEP bool true to use OAEP padding (PKCS #1 v2), false to use PKCS #1 type 2 padding
return byte[]

ExportCspBlob() public method

Exports a blob containing the key information associated with an RSACryptoServiceProvider object.
public ExportCspBlob ( bool includePrivateParameters ) : byte[]
includePrivateParameters bool
return byte[]

ExportParameters() public method

Exports the RSAParameters
public ExportParameters ( bool includePrivateParameters ) : RSAParameters
includePrivateParameters bool
return RSAParameters

HashData() protected method

protected HashData ( Stream data, HashAlgorithmName hashAlgorithm ) : byte[]
data System.IO.Stream
hashAlgorithm HashAlgorithmName
return byte[]

HashData() protected method

protected HashData ( byte data, int offset, int count, HashAlgorithmName hashAlgorithm ) : byte[]
data byte
offset int
count int
hashAlgorithm HashAlgorithmName
return byte[]

ImportCspBlob() public method

Imports a blob that represents RSA key information
public ImportCspBlob ( byte keyBlob ) : void
keyBlob byte
return void

ImportParameters() public method

Imports the specified RSAParameters
public ImportParameters ( RSAParameters parameters ) : void
parameters RSAParameters
return void

RSACryptoServiceProvider() public method

public RSACryptoServiceProvider ( ) : System.Diagnostics
return System.Diagnostics

RSACryptoServiceProvider() public method

public RSACryptoServiceProvider ( CspParameters parameters ) : System.Diagnostics
parameters CspParameters
return System.Diagnostics

RSACryptoServiceProvider() public method

public RSACryptoServiceProvider ( int dwKeySize ) : System.Diagnostics
dwKeySize int
return System.Diagnostics

RSACryptoServiceProvider() public method

public RSACryptoServiceProvider ( int dwKeySize, CspParameters parameters ) : System.Diagnostics
dwKeySize int
parameters CspParameters
return System.Diagnostics

SignData() public method

Computes the hash value of a subset of the specified byte array using the specified hash algorithm, and signs the resulting hash value.
public SignData ( Stream inputStream, Object halg ) : byte[]
inputStream System.IO.Stream The input data for which to compute the hash
halg Object The hash algorithm to use to create the hash value.
return byte[]

SignData() public method

Computes the hash value of a subset of the specified byte array using the specified hash algorithm, and signs the resulting hash value.
public SignData ( byte buffer, Object halg ) : byte[]
buffer byte The input data for which to compute the hash
halg Object The hash algorithm to use to create the hash value.
return byte[]

SignData() public method

Computes the hash value of a subset of the specified byte array using the specified hash algorithm, and signs the resulting hash value.
public SignData ( byte buffer, int offset, int count, object halg ) : byte[]
buffer byte The input data for which to compute the hash
offset int The offset into the array from which to begin using data
count int The number of bytes in the array to use as data.
halg object The hash algorithm to use to create the hash value.
return byte[]

SignHash() public method

public SignHash ( byte hash, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding ) : byte[]
hash byte
hashAlgorithm HashAlgorithmName
padding RSASignaturePadding
return byte[]

SignHash() public method

Computes the hash value of a subset of the specified byte array using the specified hash algorithm, and signs the resulting hash value.
public SignHash ( byte rgbHash, string str ) : byte[]
rgbHash byte The input data for which to compute the hash
str string The hash algorithm to use to create the hash value.
return byte[]

VerifyData() public method

Verifies the signature of a hash value.
public VerifyData ( byte buffer, object halg, byte signature ) : bool
buffer byte
halg object
signature byte
return bool

VerifyHash() public method

public VerifyHash ( byte hash, byte signature, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding ) : bool
hash byte
signature byte
hashAlgorithm HashAlgorithmName
padding RSASignaturePadding
return bool

VerifyHash() public method

Verifies the signature of a hash value.
public VerifyHash ( byte rgbHash, string str, byte rgbSignature ) : bool
rgbHash byte
str string
rgbSignature byte
return bool