48 if (
value != safeProvHandle)
50 if (safeProvHandle !=
null)
85 if (
value != safeKeyHandle)
94 [SupportedOSPlatform(
"windows")]
128 if (
value != persistKeyInCsp)
140 return keyParameter[0] == 1;
162 return "RSA-PKCS1-KeyEx";
180 [SupportedOSPlatform(
"windows")]
182 : this(dwKeySize, parameters, useDefaultKeySize: false)
186 [SupportedOSPlatform(
"windows")]
188 : this(0, parameters, useDefaultKeySize: true)
199 _keySize = (useDefaultKeySize ? 1024 : keySize);
213 if (rgb.Length != keySize / 8)
218 return decryptedData;
223 return base.DecryptValue(rgb);
226 protected override void Dispose(
bool disposing)
251 if (num - 42 < rgb.Length)
253 throw (-2146893820).ToCryptographicException();
256 byte[] pbEncryptedKey =
null;
258 return pbEncryptedKey;
263 return base.EncryptValue(rgb);
274 return cspBlob.ToRSAParameters(includePrivateParameters);
280 return safeProvHandle;
302 byte[] keyBlob = parameters.ToKeyBlob();
309 base.ImportEncryptedPkcs8PrivateKey(passwordBytes,
source, out bytesRead);
315 base.ImportEncryptedPkcs8PrivateKey(password,
source, out bytesRead);
338 byte[] rgbHash = hashAlgorithm.
ComputeHash(inputStream);
356 private byte[]
SignHash(
byte[] rgbHash,
int calgHash)
366 return VerifyHash(rgbHash, calgHash, signature);
375 if (rgbSignature ==
null)
380 return VerifyHash(rgbHash, calgHash, rgbSignature);
383 private bool VerifyHash(
byte[] rgbHash,
int calgHash,
byte[] rgbSignature)
398 if (keyBlob[11] != 49 || keyBlob[10] != 65 || keyBlob[9] != 83 || keyBlob[8] != 82)
408 return hashAlgorithm2.ComputeHash(data,
offset,
count);
414 return hashAlgorithm2.ComputeHash(data);
419 return hashAlgorithm.Name
switch
432 return hashAlgorithm.Name
switch
455 return Encrypt(data, fOAEP:
false);
459 return Encrypt(data, fOAEP:
true);
476 return Decrypt(data, fOAEP:
false);
480 return Decrypt(data, fOAEP:
true);
491 if (
string.IsNullOrEmpty(hashAlgorithm.
Name))
512 if (signature ==
null)
516 if (
string.IsNullOrEmpty(hashAlgorithm.
Name))
static void AcquireCsp(CspParameters cspParameters, out SafeProvHandle safeProvHandle)
static SafeKeyHandle GetKeyPairHelper(CspAlgorithmType keyType, CspParameters parameters, int keySize, SafeProvHandle safeProvHandle)
static bool GetPersistKeyInCsp(SafeProvHandle safeProvHandle)
static void SetPersistKeyInCsp(SafeProvHandle safeProvHandle, bool fPersistKeyInCsp)
static SafeProvHandle CreateProvHandle(CspParameters parameters, bool randomKeyContainer)
static int ObjToHashAlgId(object hashAlg)
static CspParameters SaveCspParameters(CspAlgorithmType keyType, CspParameters userParameters, CspProviderFlags defaultFlags, out bool randomKeyContainer)
static int NameOrOidToHashAlgId(string nameOrOid, OidGroup oidGroup)
static void DecryptKey(SafeKeyHandle safeKeyHandle, byte[] encryptedData, int encryptedDataLength, bool fOAEP, out byte[] decryptedData)
static void ImportKeyBlob(SafeProvHandle saveProvHandle, CspProviderFlags flags, bool addNoSaltFlag, byte[] keyBlob, out SafeKeyHandle safeKeyHandle)
static byte[] SignValue(SafeProvHandle hProv, SafeKeyHandle hKey, int keyNumber, int calgKey, int calgHash, byte[] hash)
static void EncryptKey(SafeKeyHandle safeKeyHandle, byte[] pbKey, int cbKey, bool foep, [NotNull] ref byte[] pbEncryptedKey)
static HashAlgorithm ObjToHashAlgorithm(object hashAlg)
static byte[] ExportKeyBlob(bool includePrivateParameters, SafeKeyHandle safeKeyHandle)
static byte[] GetKeyParameter(SafeKeyHandle safeKeyHandle, int keyParam)
static bool VerifySign(SafeProvHandle hProv, SafeKeyHandle hKey, int calgKey, int calgHash, byte[] hash, byte[] signature)
static int ReadInt32LittleEndian(ReadOnlySpan< byte > source)
static string Cryptography_RSA_DecryptWrongSize
static string Cryptography_UnknownHashAlgorithm
static string Cryptography_CSP_NoPrivateKey
static string Cryptography_InvalidPaddingMode
static string Cryptography_HashAlgorithmNameNullOrEmpty
byte[] ComputeHash(byte[] buffer)
override KeySizes[] LegalKeySizes
override byte[] EncryptValue(byte[] rgb)
SafeKeyHandle _safeKeyHandle
RSACryptoServiceProvider(int keySize, CspParameters parameters, bool useDefaultKeySize)
byte[] SignHash(byte[] rgbHash, string? str)
CspKeyContainerInfo CspKeyContainerInfo
override byte[] SignHash(byte[] hash, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
byte[] SignHash(byte[] rgbHash, int calgHash)
readonly CspParameters _parameters
static HashAlgorithm GetHashAlgorithm(HashAlgorithmName hashAlgorithm)
readonly bool _randomKeyContainer
byte[] Decrypt(byte[] rgb, bool fOAEP)
SafeProvHandle _safeProvHandle
byte[] SignData(byte[] buffer, int offset, int count, object halg)
override bool VerifyHash(byte[] hash, byte[] signature, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
bool VerifyData(byte[] buffer, object halg, byte[] signature)
byte[] ExportCspBlob(bool includePrivateParameters)
override string SignatureAlgorithm
override byte[] Encrypt(byte[] data, RSAEncryptionPadding padding)
RSACryptoServiceProvider(int dwKeySize, CspParameters? parameters)
override void ImportParameters(RSAParameters parameters)
override? string KeyExchangeAlgorithm
override byte[] HashData(Stream data, HashAlgorithmName hashAlgorithm)
RSACryptoServiceProvider(int dwKeySize)
override byte[] HashData(byte[] data, int offset, int count, HashAlgorithmName hashAlgorithm)
RSACryptoServiceProvider()
void ImportCspBlob(byte[] keyBlob)
override void ImportEncryptedPkcs8PrivateKey(ReadOnlySpan< char > password, ReadOnlySpan< byte > source, out int bytesRead)
override void ImportEncryptedPkcs8PrivateKey(ReadOnlySpan< byte > passwordBytes, ReadOnlySpan< byte > source, out int bytesRead)
static bool IsPublic(byte[] keyBlob)
static bool UseMachineKeyStore
static volatile CspProviderFlags s_useMachineKeyStore
static Exception HashAlgorithmNameNullOrEmpty()
static Exception PaddingModeNotSupported()
byte[] Encrypt(byte[] rgb, bool fOAEP)
override byte[] DecryptValue(byte[] rgb)
byte[] SignData(byte[] buffer, object halg)
override RSAParameters ExportParameters(bool includePrivateParameters)
SafeProvHandle AcquireSafeProviderHandle()
RSACryptoServiceProvider(CspParameters? parameters)
bool VerifyHash(byte[] rgbHash, string str, byte[] rgbSignature)
override void Dispose(bool disposing)
bool VerifyHash(byte[] rgbHash, int calgHash, byte[] rgbSignature)
byte[] SignData(Stream inputStream, object halg)
override byte[] Decrypt(byte[] data, RSAEncryptionPadding padding)
static int GetAlgorithmId(HashAlgorithmName hashAlgorithm)
SafeKeyHandle SafeKeyHandle
static RSAEncryptionPadding OaepSHA1
static RSAEncryptionPadding Pkcs1
static RSASignaturePadding Pkcs1
static new SHA256 Create()
static new SHA384 Create()
static new SHA512 Create()
override void Dispose(bool disposing)
override void Dispose(bool disposing)