Class CpRSACryptoServiceProvider
Inherited Members
Namespace: CryptoPro.Security.Cryptography
Assembly: CryptoPro.Security.Cryptography.dll
Syntax
public sealed class CpRSACryptoServiceProvider : CpRSA, IDisposable, ICpCspAsymmetricAlgorithm
Constructors
CpRSACryptoServiceProvider()
Declaration
public CpRSACryptoServiceProvider()
CpRSACryptoServiceProvider(CpCspParameters)
Declaration
public CpRSACryptoServiceProvider(CpCspParameters parameters)
Parameters
Type | Name | Description |
---|---|---|
CpCspParameters | parameters |
CpRSACryptoServiceProvider(int)
Declaration
public CpRSACryptoServiceProvider(int dwKeySize)
Parameters
Type | Name | Description |
---|---|---|
int | dwKeySize |
CpRSACryptoServiceProvider(int, CpCspParameters)
Declaration
public CpRSACryptoServiceProvider(int dwKeySize, CpCspParameters parameters)
Parameters
Type | Name | Description |
---|---|---|
int | dwKeySize | |
CpCspParameters | parameters |
Properties
CipherOid
Параметры шифрования
Declaration
public string CipherOid { get; set; }
Property Value
Type | Description |
---|---|
string |
ContainerCertificate
Получение/установка сертификата в конейнер.
Declaration
public byte[] ContainerCertificate { get; set; }
Property Value
Type | Description |
---|---|
byte[] | Возвращается хранимый сертификат или null, если сертификат в контейнере отсутствует. |
CspKeyContainerInfo
Получает информацию о CSP CspKeyContainerInfo, в котором хранится ключевая пара.
Declaration
public CpCspKeyContainerInfo CspKeyContainerInfo { get; }
Property Value
Type | Description |
---|---|
CpCspKeyContainerInfo |
Handle
Gets a copy to a native HCRYPTPROV handle.
Declaration
public nint Handle { get; }
Property Value
Type | Description |
---|---|
nint |
HandleNoDuplicate
Gets a native HCRYPTPROV handle.
Declaration
public nint HandleNoDuplicate { get; }
Property Value
Type | Description |
---|---|
nint |
KeyExchangeAlgorithm
When overridden in a derived class, gets the name of the key exchange algorithm. Otherwise, throws an NotImplementedException.
Declaration
public override string KeyExchangeAlgorithm { get; }
Property Value
Type | Description |
---|---|
string | The name of the key exchange algorithm. |
Overrides
KeySize
Gets or sets the size, in bits, of the key modulus used by the asymmetric algorithm.
Declaration
public override int KeySize { get; }
Property Value
Type | Description |
---|---|
int | The size, in bits, of the key modulus used by the asymmetric algorithm. |
Overrides
Exceptions
Type | Condition |
---|---|
CryptographicException | The key modulus size is invalid. |
KeySpec
Gets a key specification.
Declaration
public int KeySpec { get; }
Property Value
Type | Description |
---|---|
int |
LegalKeySizes
Gets the key sizes that are supported by the asymmetric algorithm.
Declaration
public override KeySizes[] LegalKeySizes { get; }
Property Value
Type | Description |
---|---|
KeySizes[] | An array that contains the key sizes supported by the asymmetric algorithm. |
Overrides
NotAfter
Срок действия закртытого ключа, указанного в KP_NOTAFTER
Declaration
public DateTimeOffset NotAfter { get; }
Property Value
Type | Description |
---|---|
DateTimeOffset |
PublicOnly
Получает значение, указывающее, не содержит ли объект Gost3410_2012_256CryptoServiceProvider только открытый ключ.
Declaration
public bool PublicOnly { get; }
Property Value
Type | Description |
---|---|
bool | true, если Gost3410_2012_256CryptoServiceProvider содержит только открытый ключ, false - иначе. |
SignatureAlgorithm
When implemented in a derived class, gets the name of the signature algorithm. Otherwise, always throws a NotImplementedException.
Declaration
public override string SignatureAlgorithm { get; }
Property Value
Type | Description |
---|---|
string | The name of the signature algorithm. |
Overrides
UseMachineKeyStore
Возвращает или устанавливает флаг того, что ключ должен храниться в STORE ключей компьютера, а не в профиле пользователя.
Declaration
public static bool UseMachineKeyStore { get; set; }
Property Value
Type | Description |
---|---|
bool | true, если ключ должен храниться в банке ключей компьютера, false - иначе. |
Remarks
Данный флаг устанавливает использование ключей из STORE пользователя
или компьютера при открытии ключей без указания данного флага.
Установка данного флага эквивалентна передаче установке флага
UseMachineKeyStore в
CspParameters. Свойство UseMachineKeyStore
устанавливается для всего кода в текущем домене, в то время как
CspParameters применимо только к объекту на который он
ссылается. Установка/сброс данного флага полезна при
имперсонализации или работе без загруженного профиля пользователя.
При инициализации объекта через конструктор CpRSACryptoServiceProvider(CpCspParameters) будут использованы именно эти параметры, в независимости от флага UseMachineKeyStore. По умолчанию значение флага из CpRSACryptoServiceProvider(CpCspParameters) устанавливется в использование ключей из хранилищи пользователя. Для использования ключей из хранилища компьютера при использовании конструктора CpRSACryptoServiceProvider(CpCspParameters) необходимо установить флаг Flags: UseMachineKeyStore.
Methods
Decrypt(byte[], bool)
Decrypt raw data, generally used for decrypting symmetric key material
Declaration
public byte[] Decrypt(byte[] rgb, bool fOAEP)
Parameters
Type | Name | Description |
---|---|---|
byte[] | rgb | encrypted data |
bool | fOAEP | true to use OAEP padding (PKCS #1 v2), false to use PKCS #1 type 2 padding |
Returns
Type | Description |
---|---|
byte[] | decrypted data |
Decrypt(byte[], RSAEncryptionPadding)
Declaration
public override byte[] Decrypt(byte[] data, RSAEncryptionPadding padding)
Parameters
Type | Name | Description |
---|---|---|
byte[] | data | |
RSAEncryptionPadding | padding |
Returns
Type | Description |
---|---|
byte[] |
Overrides
Dispose(bool)
Dispose the key handles
Declaration
protected override void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
bool | disposing |
Overrides
Encrypt(byte[], bool)
Encrypt raw data, generally used for encrypting symmetric key material.
Declaration
public byte[] Encrypt(byte[] rgb, bool fOAEP)
Parameters
Type | Name | Description |
---|---|---|
byte[] | rgb | raw data to encrypt |
bool | fOAEP | true to use OAEP padding (PKCS #1 v2), false to use PKCS #1 type 2 padding |
Returns
Type | Description |
---|---|
byte[] | Encrypted key |
Remarks
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.
Encrypt(byte[], RSAEncryptionPadding)
Declaration
public override byte[] Encrypt(byte[] data, RSAEncryptionPadding padding)
Parameters
Type | Name | Description |
---|---|---|
byte[] | data | |
RSAEncryptionPadding | padding |
Returns
Type | Description |
---|---|
byte[] |
Overrides
ExportCspBlob()
Declaration
public byte[] ExportCspBlob()
Returns
Type | Description |
---|---|
byte[] |
ExportCspBlob(bool)
Exports a blob containing the key information associated with an RSACryptoServiceProvider object.
Declaration
public byte[] ExportCspBlob(bool includePrivateParameters)
Parameters
Type | Name | Description |
---|---|---|
bool | includePrivateParameters |
Returns
Type | Description |
---|---|
byte[] |
ExportParameters(bool)
Exports the RSAParameters
Declaration
public override RSAParameters ExportParameters(bool includePrivateParameters)
Parameters
Type | Name | Description |
---|---|---|
bool | includePrivateParameters |
Returns
Type | Description |
---|---|
RSAParameters |
Overrides
ImportCspBlob(byte[])
Imports a blob that represents RSA key information
Declaration
public void ImportCspBlob(byte[] keyBlob)
Parameters
Type | Name | Description |
---|---|---|
byte[] | keyBlob |
ImportParameters(RSAParameters)
Imports the specified RSAParameters
Declaration
public override void ImportParameters(RSAParameters parameters)
Parameters
Type | Name | Description |
---|---|---|
RSAParameters | parameters |
Overrides
ImportSubjectPublicKeyInfo(ReadOnlySpan<byte>, out int)
When overriden in a derived class, imports the public key from an X.509 SubjectPublicKeyInfo structure after decryption, replacing the keys for this object.
Declaration
public override void ImportSubjectPublicKeyInfo(ReadOnlySpan<byte> source, out int bytesRead)
Parameters
Type | Name | Description |
---|---|---|
ReadOnlySpan<byte> | source | The bytes of an X.509 SubjectPublicKeyInfo structure in the ASN.1-DER encoding. |
int | bytesRead | When this method returns, contains a value that indicates the number of bytes read from |
Overrides
Exceptions
Type | Condition |
---|---|
CryptographicException | The contents of -or- The contents of -or- The contents of -or- The algorithm-specific key import failed. |
NotImplementedException | A derived type has not overriden this member. |
SignData(byte[], int, int, object)
Computes the hash value of a subset of the specified byte array using the specified hash algorithm, and signs the resulting hash value.
Declaration
public byte[] SignData(byte[] buffer, int offset, int count, object halg)
Parameters
Type | Name | Description |
---|---|---|
byte[] | buffer | The input data for which to compute the hash |
int | offset | The offset into the array from which to begin using data |
int | count | The number of bytes in the array to use as data. |
object | halg | The hash algorithm to use to create the hash value. |
Returns
Type | Description |
---|---|
byte[] | The RSA signature for the specified data. |
SignData(byte[], object)
Computes the hash value of a subset of the specified byte array using the specified hash algorithm, and signs the resulting hash value.
Declaration
public byte[] SignData(byte[] buffer, object halg)
Parameters
Type | Name | Description |
---|---|---|
byte[] | buffer | The input data for which to compute the hash |
object | halg | The hash algorithm to use to create the hash value. |
Returns
Type | Description |
---|---|
byte[] | The RSA signature for the specified data. |
SignData(Stream, object)
Computes the hash value of a subset of the specified byte array using the specified hash algorithm, and signs the resulting hash value.
Declaration
public byte[] SignData(Stream inputStream, object halg)
Parameters
Type | Name | Description |
---|---|---|
Stream | inputStream | The input data for which to compute the hash |
object | halg | The hash algorithm to use to create the hash value. |
Returns
Type | Description |
---|---|
byte[] | The RSA signature for the specified data. |
SignHash(byte[], string?)
Computes the hash value of a subset of the specified byte array using the specified hash algorithm, and signs the resulting hash value.
Declaration
public byte[] SignHash(byte[] rgbHash, string? str)
Parameters
Type | Name | Description |
---|---|---|
byte[] | rgbHash | The input data for which to compute the hash |
string | str | The hash algorithm to use to create the hash value. |
Returns
Type | Description |
---|---|
byte[] | The RSA signature for the specified data. |
TrySignHashCore(ReadOnlySpan<byte>, Span<byte>, CpHashAlgorithmName, RSASignaturePadding, out int)
Declaration
protected override bool TrySignHashCore(ReadOnlySpan<byte> rgbHash, Span<byte> signature, CpHashAlgorithmName hashAlgorithm, RSASignaturePadding padding, out int bytesWritten)
Parameters
Type | Name | Description |
---|---|---|
ReadOnlySpan<byte> | rgbHash | |
Span<byte> | signature | |
CpHashAlgorithmName | hashAlgorithm | |
RSASignaturePadding | padding | |
int | bytesWritten |
Returns
Type | Description |
---|---|
bool |
Overrides
VerifyHashCore(ReadOnlySpan<byte>, ReadOnlySpan<byte>, CpHashAlgorithmName, RSASignaturePadding)
Verifies that a digital signature is valid for the provided hash.
Declaration
protected override bool VerifyHashCore(ReadOnlySpan<byte> rgbHash, ReadOnlySpan<byte> rgbSignature, CpHashAlgorithmName hashAlgorithmName, RSASignaturePadding padding)
Parameters
Type | Name | Description |
---|---|---|
ReadOnlySpan<byte> | rgbHash | |
ReadOnlySpan<byte> | rgbSignature | |
CpHashAlgorithmName | hashAlgorithmName | |
RSASignaturePadding | padding |
Returns
Type | Description |
---|---|
bool | true if the digital signature is valid for the provided data; otherwise, false. |
Overrides
Exceptions
Type | Condition |
---|---|
CryptographicException | An error occurred in the verification operation. |