13[UnsupportedOSPlatform(
"browser")]
20 [RequiresUnreferencedCode(
"The default algorithm implementations might be removed, use strong type references like 'RSA.Create()' instead.")]
31 rSA.KeySize = keySizeInBits;
96 bytesWritten =
array.Length;
109 bytesWritten =
array.Length;
133 bytesWritten = array2.Length;
146 bytesWritten =
array.Length;
179 return SignData(data, 0, data.Length, hashAlgorithm, padding);
188 if (offset < 0 || offset > data.Length)
192 if (count < 0 || count > data.Length -
offset)
196 if (
string.IsNullOrEmpty(hashAlgorithm.
Name))
205 return SignHash(hash, hashAlgorithm, padding);
214 if (
string.IsNullOrEmpty(hashAlgorithm.
Name))
222 byte[] hash =
HashData(data, hashAlgorithm);
223 return SignHash(hash, hashAlgorithm, padding);
228 if (
string.IsNullOrEmpty(hashAlgorithm.
Name))
250 return VerifyData(data, 0, data.Length, signature, hashAlgorithm, padding);
259 if (offset < 0 || offset > data.Length)
263 if (count < 0 || count > data.Length -
offset)
267 if (signature ==
null)
271 if (
string.IsNullOrEmpty(hashAlgorithm.
Name))
280 return VerifyHash(hash, signature, hashAlgorithm, padding);
289 if (signature ==
null)
293 if (
string.IsNullOrEmpty(hashAlgorithm.
Name))
301 byte[] hash =
HashData(data, hashAlgorithm);
302 return VerifyHash(hash, signature, hashAlgorithm, padding);
307 if (
string.IsNullOrEmpty(hashAlgorithm.
Name))
318 int bytesWritten = 0;
331 num = checked(num * 2);
338 return asnWriter.
Encode();
350 return asnWriter.
Encode();
366 int bytesWritten2 = 0;
367 fixed (
byte* ptr =
array)
373 num = checked(num * 2);
395 int num = checked(5 *
KeySize) / 8;
400 int bytesWritten = 0;
401 fixed (
byte* ptr =
array)
407 num = checked(num * 2);
422 if (pbeParameters ==
null)
434 if (pbeParameters ==
null)
453 fixed (
byte* ptr6 = rsaParameters.
D)
455 fixed (
byte* ptr5 = rsaParameters.
P)
457 fixed (
byte* ptr4 = rsaParameters.
Q)
459 fixed (
byte* ptr3 = rsaParameters.
DP)
461 fixed (
byte* ptr2 = rsaParameters.
DQ)
463 fixed (
byte* ptr = rsaParameters.
InverseQ)
487 bytesRead = bytesRead2;
502 bytesRead = bytesConsumed;
523 fixed (
byte* ptr6 = ret.D)
525 fixed (
byte* ptr5 = ret.P)
527 fixed (
byte* ptr4 = ret.Q)
529 fixed (
byte* ptr3 = ret.DP)
531 fixed (
byte* ptr2 = ret.DQ)
533 fixed (
byte* ptr = ret.InverseQ)
564 bytesRead = bytesRead2;
571 fixed (
byte* ptr6 =
key.D)
573 fixed (
byte* ptr5 =
key.P)
575 fixed (
byte* ptr4 =
key.Q)
577 fixed (
byte* ptr3 =
key.DP)
579 fixed (
byte* ptr2 =
key.DQ)
581 fixed (
byte* ptr =
key.InverseQ)
597 bytesRead = bytesRead2;
603 fixed (
byte* ptr6 =
key.D)
605 fixed (
byte* ptr5 =
key.P)
607 fixed (
byte* ptr4 =
key.Q)
609 fixed (
byte* ptr3 =
key.DP)
611 fixed (
byte* ptr2 =
key.DQ)
613 fixed (
byte* ptr =
key.InverseQ)
629 bytesRead = bytesRead2;
636 if (label.SequenceEqual(
"RSA PRIVATE KEY"))
638 return ImportRSAPrivateKey;
640 if (label.SequenceEqual(
"PRIVATE KEY"))
642 return ImportPkcs8PrivateKey;
644 if (label.SequenceEqual(
"RSA PUBLIC KEY"))
646 return ImportRSAPublicKey;
692 int sizeHint = (array.Length + 1) / 2;
700 rSAParameters.Modulus =
array;
701 rSAParameters.Exponent = exponent;
705 rSAParameters.DP = dP;
706 rSAParameters.DQ = dQ;
707 rSAParameters.InverseQ = inverseQ;
715 int num2 = 100 + num;
716 if (includePrivateParameters)
718 num2 += 76 + 5 * num / 2;
722 stringBuilder.
Append(
"<RSAKeyValue>");
725 if (includePrivateParameters)
734 stringBuilder.
Append(
"</RSAKeyValue>");
static void ImportPem(ReadOnlySpan< char > input, FindImportActionFunc callback)
delegate void ImportKeyAction(ReadOnlySpan< byte > source, out int bytesRead)
static unsafe void Clear(Array array)
static ArrayPool< T > Shared
static string Cryptography_Der_Invalid_Encoding
static string Format(string resourceFormat, object p1)
static string NotSupported_Method
static string Cryptography_InvalidFromXmlString
static string Cryptography_HashAlgorithmNameNullOrEmpty
static string NotSupported_SubclassOverride
static ? object CreateFromName(string name, params object?[]? args)
static void Return(byte[] array, int clearSize=-1)
static byte[] Rent(int minimumLength)
static void ZeroMemory(Span< byte > buffer)
static void ValidatePbeParameters(PbeParameters pbeParameters, ReadOnlySpan< char > password, ReadOnlySpan< byte > passwordBytes)
static Exception HashAlgorithmNameNullOrEmpty()
override bool TryExportPkcs8PrivateKey(Span< byte > destination, out int bytesWritten)
virtual byte[] SignData(Stream data, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
bool VerifyData(Stream data, byte[] signature, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
unsafe override void ImportEncryptedPkcs8PrivateKey(ReadOnlySpan< char > password, ReadOnlySpan< byte > source, out int bytesRead)
static RSA Create(int keySizeInBits)
virtual bool VerifyHash(ReadOnlySpan< byte > hash, ReadOnlySpan< byte > signature, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
static new? RSA Create(string algName)
virtual byte[] EncryptValue(byte[] rgb)
virtual bool TrySignData(ReadOnlySpan< byte > data, Span< byte > destination, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding, out int bytesWritten)
virtual byte[] DecryptValue(byte[] rgb)
virtual byte[] Decrypt(byte[] data, RSAEncryptionPadding padding)
virtual bool TryHashData(ReadOnlySpan< byte > data, Span< byte > destination, HashAlgorithmName hashAlgorithm, out int bytesWritten)
virtual bool TryExportRSAPublicKey(Span< byte > destination, out int bytesWritten)
unsafe override void ImportSubjectPublicKeyInfo(ReadOnlySpan< byte > source, out int bytesRead)
override void ImportFromPem(ReadOnlySpan< char > input)
override bool TryExportEncryptedPkcs8PrivateKey(ReadOnlySpan< char > password, PbeParameters pbeParameters, Span< byte > destination, out int bytesWritten)
virtual bool VerifyData(ReadOnlySpan< byte > data, ReadOnlySpan< byte > signature, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
override void ImportFromEncryptedPem(ReadOnlySpan< char > input, ReadOnlySpan< byte > passwordBytes)
unsafe override bool TryExportSubjectPublicKeyInfo(Span< byte > destination, out int bytesWritten)
unsafe override void ImportEncryptedPkcs8PrivateKey(ReadOnlySpan< byte > passwordBytes, ReadOnlySpan< byte > source, out int bytesRead)
virtual byte[] Encrypt(byte[] data, RSAEncryptionPadding padding)
virtual bool TrySignHash(ReadOnlySpan< byte > hash, Span< byte > destination, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding, out int bytesWritten)
virtual bool TryEncrypt(ReadOnlySpan< byte > data, Span< byte > destination, RSAEncryptionPadding padding, out int bytesWritten)
static void ClearPrivateParameters(in RSAParameters rsaParameters)
virtual bool TryExportRSAPrivateKey(Span< byte > destination, out int bytesWritten)
RSAParameters ExportParameters(bool includePrivateParameters)
virtual byte[] HashData(byte[] data, int offset, int count, HashAlgorithmName hashAlgorithm)
unsafe override void ImportPkcs8PrivateKey(ReadOnlySpan< byte > source, out int bytesRead)
virtual byte[] ExportRSAPrivateKey()
virtual bool TryDecrypt(ReadOnlySpan< byte > data, Span< byte > destination, RSAEncryptionPadding padding, out int bytesWritten)
virtual unsafe void ImportRSAPublicKey(ReadOnlySpan< byte > source, out int bytesRead)
AsnWriter WritePkcs1PublicKey()
override? string KeyExchangeAlgorithm
virtual byte[] ExportRSAPublicKey()
override void ImportFromEncryptedPem(ReadOnlySpan< char > input, ReadOnlySpan< char > password)
byte[] SignData(byte[] data, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
static byte[] ReadRequiredElement(ref XmlKeyHelper.ParseState state, string name, int sizeHint=-1)
unsafe AsnWriter WritePkcs8PrivateKey()
static Exception DerivedClassMustOverride()
virtual bool VerifyData(byte[] data, int offset, int count, byte[] signature, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
virtual byte[] HashData(Stream data, HashAlgorithmName hashAlgorithm)
bool VerifyData(byte[] data, byte[] signature, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
override void FromXmlString(string xmlString)
virtual byte[] SignHash(byte[] hash, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
override string ToXmlString(bool includePrivateParameters)
virtual bool VerifyHash(byte[] hash, byte[] signature, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
static RSA Create(RSAParameters parameters)
unsafe AsnWriter WritePkcs1PrivateKey()
void ImportParameters(RSAParameters parameters)
override string SignatureAlgorithm
override bool TryExportEncryptedPkcs8PrivateKey(ReadOnlySpan< byte > passwordBytes, PbeParameters pbeParameters, Span< byte > destination, out int bytesWritten)
virtual byte[] SignData(byte[] data, int offset, int count, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
virtual unsafe void ImportRSAPrivateKey(ReadOnlySpan< byte > source, out int bytesRead)
static void WriteCryptoBinary(string name, int value, StringBuilder builder)
static byte[] ReadCryptoBinary(ref ParseState state, string name, int sizeHint=-1)
static ParseState ParseDocument(string xmlString)
override string ToString()
StringBuilder Append(char value, int repeatCount)
void CopyTo(Span< T > destination)