10[UnsupportedOSPlatform(
"browser")]
13 private static readonly
string[]
s_validOids =
new string[1] {
"1.2.840.10045.2.1" };
19 [RequiresUnreferencedCode(
"The default algorithm implementations might be removed, use strong type references like 'RSA.Create()' instead.")]
22 if (algorithm ==
null)
55 return SignData(data, 0, data.Length, hashAlgorithm);
64 if (offset < 0 || offset > data.Length)
68 if (count < 0 || count > data.Length -
offset)
72 if (
string.IsNullOrEmpty(hashAlgorithm.
Name))
86 if (offset < 0 || offset > data.Length)
90 if (count < 0 || count > data.Length -
offset)
94 if (
string.IsNullOrEmpty(hashAlgorithm.
Name))
98 if (!signatureFormat.IsKnownValue())
111 int bytesWritten = 0;
123 byte[] result =
destination.Slice(0, bytesWritten).ToArray();
146 if (
string.IsNullOrEmpty(hashAlgorithm.
Name))
150 if (!signatureFormat.IsKnownValue())
154 return SignDataCore(data, hashAlgorithm, signatureFormat);
163 if (
string.IsNullOrEmpty(hashAlgorithm.
Name))
167 if (!signatureFormat.IsKnownValue())
171 return SignDataCore(data, hashAlgorithm, signatureFormat);
186 if (!signatureFormat.IsKnownValue())
199 int bytesWritten = 0;
211 byte[] result =
destination.Slice(0, bytesWritten).ToArray();
230 if (
string.IsNullOrEmpty(hashAlgorithm.
Name))
241 if (
string.IsNullOrEmpty(hashAlgorithm.
Name))
245 if (!signatureFormat.IsKnownValue())
265 if (
string.IsNullOrEmpty(hashAlgorithm.
Name))
269 byte[] hash =
HashData(data, hashAlgorithm);
279 return VerifyData(data, 0, data.Length, signature, hashAlgorithm);
288 if (offset < 0 || offset > data.Length)
292 if (count < 0 || count > data.Length -
offset)
296 if (signature ==
null)
300 if (
string.IsNullOrEmpty(hashAlgorithm.
Name))
314 if (offset < 0 || offset > data.Length)
318 if (count < 0 || count > data.Length -
offset)
322 if (signature ==
null)
326 if (
string.IsNullOrEmpty(hashAlgorithm.
Name))
330 if (!signatureFormat.IsKnownValue())
343 if (signature ==
null)
347 if (
string.IsNullOrEmpty(hashAlgorithm.
Name))
351 if (!signatureFormat.IsKnownValue())
355 return VerifyDataCore(data, signature, hashAlgorithm, signatureFormat);
360 if (
string.IsNullOrEmpty(hashAlgorithm.
Name))
371 if (
string.IsNullOrEmpty(hashAlgorithm.
Name))
375 if (!signatureFormat.IsKnownValue())
379 return VerifyDataCore(data, signature, hashAlgorithm, signatureFormat);
395 if (signature ==
null)
399 if (
string.IsNullOrEmpty(hashAlgorithm.
Name))
403 byte[] hash =
HashData(data, hashAlgorithm);
413 if (signature ==
null)
417 if (
string.IsNullOrEmpty(hashAlgorithm.
Name))
421 if (!signatureFormat.IsKnownValue())
425 return VerifyDataCore(data, signature, hashAlgorithm, signatureFormat);
436 public abstract bool VerifyHash(
byte[] hash,
byte[] signature);
460 bytesWritten = array2.Length;
483 if (!signatureFormat.IsKnownValue())
508 if (signature ==
null)
512 if (!signatureFormat.IsKnownValue())
521 if (!signatureFormat.IsKnownValue())
530 byte[]
array = this.ConvertSignatureToIeeeP1363(signatureFormat, signature);
540 if (
TryHashData(data, tmp, hashAlgorithm, out var bytesWritten))
542 return tmp.
Slice(0, bytesWritten);
570 if (pbeParameters ==
null)
576 fixed (
byte* ptr = ecParameters.
D)
593 if (pbeParameters ==
null)
599 fixed (
byte* ptr = ecParameters.
D)
617 fixed (
byte* ptr = ecParameters.
D)
635 return asnWriter.TryEncode(
destination, out bytesWritten);
641 fixed (
byte* ptr = ret.D)
646 bytesRead = bytesRead2;
658 fixed (
byte* ptr = ret.D)
663 bytesRead = bytesRead2;
675 fixed (
byte* ptr = ret.D)
680 bytesRead = bytesRead2;
693 bytesRead = bytesRead2;
700 fixed (
byte* ptr = parameters.
D)
705 bytesRead = bytesRead2;
717 fixed (
byte* ptr = ecParameters.
D)
722 return asnWriter.
Encode();
734 fixed (
byte* ptr = ecParameters.
D)
760 return signatureFormat
switch
772 if (label.SequenceEqual(
"PRIVATE KEY"))
774 return ImportPkcs8PrivateKey;
776 if (label.SequenceEqual(
"PUBLIC KEY"))
778 return ImportSubjectPublicKeyInfo;
static int GetMaxDerSignatureSize(int fieldSizeBits)
static int BitsToBytes(int bitLength)
static byte[] ConvertFromIeeeP1363Signature(byte[] signature, DSASignatureFormat targetFormat)
static bool TryCopyToDestination(this ReadOnlySpan< byte > source, Span< byte > destination, out int bytesWritten)
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_ECXmlSerializationFormatRequired
static string Cryptography_InvalidKeySize
static string Cryptography_HashAlgorithmNameNullOrEmpty
static string NotSupported_SubclassOverride
static ? object CreateFromName(string name, params object?[]? args)
static void ZeroMemory(Span< byte > buffer)
override? string KeyExchangeAlgorithm
virtual unsafe byte[] ExportECPrivateKey()
virtual byte[] SignData(Stream data, HashAlgorithmName hashAlgorithm)
override void ImportFromEncryptedPem(ReadOnlySpan< char > input, ReadOnlySpan< char > password)
unsafe override void ImportEncryptedPkcs8PrivateKey(ReadOnlySpan< byte > passwordBytes, ReadOnlySpan< byte > source, out int bytesRead)
virtual void GenerateKey(ECCurve curve)
virtual bool VerifyData(byte[] data, int offset, int count, byte[] signature, HashAlgorithmName hashAlgorithm)
virtual bool TrySignHashCore(ReadOnlySpan< byte > hash, Span< byte > destination, DSASignatureFormat signatureFormat, out int bytesWritten)
virtual bool TrySignData(ReadOnlySpan< byte > data, Span< byte > destination, HashAlgorithmName hashAlgorithm, out int bytesWritten)
byte[] SignHash(byte[] hash, DSASignatureFormat signatureFormat)
virtual bool TrySignHash(ReadOnlySpan< byte > hash, Span< byte > destination, out int bytesWritten)
override void ImportFromEncryptedPem(ReadOnlySpan< char > input, ReadOnlySpan< byte > passwordBytes)
virtual bool TrySignDataCore(ReadOnlySpan< byte > data, Span< byte > destination, HashAlgorithmName hashAlgorithm, DSASignatureFormat signatureFormat, out int bytesWritten)
override void FromXmlString(string xmlString)
byte[] SignData(byte[] data, HashAlgorithmName hashAlgorithm, DSASignatureFormat signatureFormat)
virtual unsafe bool TryExportECPrivateKey(Span< byte > destination, out int bytesWritten)
ReadOnlySpan< byte > HashSpanToTmp(ReadOnlySpan< byte > data, HashAlgorithmName hashAlgorithm, Span< byte > tmp)
virtual byte[] SignHashCore(ReadOnlySpan< byte > hash, DSASignatureFormat signatureFormat)
bool VerifyData(byte[] data, byte[] signature, HashAlgorithmName hashAlgorithm, DSASignatureFormat signatureFormat)
static readonly string[] s_validOids
static ECDsa Create(ECParameters parameters)
bool VerifyData(byte[] data, byte[] signature, HashAlgorithmName hashAlgorithm)
override void ImportFromPem(ReadOnlySpan< char > input)
static ECDsa Create(ECCurve curve)
virtual byte[] HashData(Stream data, HashAlgorithmName hashAlgorithm)
override bool TryExportSubjectPublicKeyInfo(Span< byte > destination, out int bytesWritten)
virtual unsafe void ImportECPrivateKey(ReadOnlySpan< byte > source, out int bytesRead)
virtual byte[] SignDataCore(Stream data, HashAlgorithmName hashAlgorithm, DSASignatureFormat signatureFormat)
unsafe override bool TryExportEncryptedPkcs8PrivateKey(ReadOnlySpan< byte > passwordBytes, PbeParameters pbeParameters, Span< byte > destination, out int bytesWritten)
virtual void ImportParameters(ECParameters parameters)
virtual byte[] SignData(byte[] data, HashAlgorithmName hashAlgorithm)
bool VerifyHash(byte[] hash, byte[] signature)
byte[] HashSpanToArray(ReadOnlySpan< byte > data, HashAlgorithmName hashAlgorithm)
static new? ECDsa Create(string algorithm)
byte[] SignData(Stream data, HashAlgorithmName hashAlgorithm, DSASignatureFormat signatureFormat)
virtual bool VerifyHash(ReadOnlySpan< byte > hash, ReadOnlySpan< byte > signature)
virtual ECParameters ExportExplicitParameters(bool includePrivateParameters)
virtual byte[] HashData(byte[] data, int offset, int count, HashAlgorithmName hashAlgorithm)
bool TrySignData(ReadOnlySpan< byte > data, Span< byte > destination, HashAlgorithmName hashAlgorithm, DSASignatureFormat signatureFormat, out int bytesWritten)
byte[] SignHash(byte[] hash)
unsafe override bool TryExportPkcs8PrivateKey(Span< byte > destination, out int bytesWritten)
unsafe override void ImportPkcs8PrivateKey(ReadOnlySpan< byte > source, out int bytesRead)
override string SignatureAlgorithm
virtual bool VerifyData(ReadOnlySpan< byte > data, ReadOnlySpan< byte > signature, HashAlgorithmName hashAlgorithm)
byte[] SignData(byte[] data, int offset, int count, HashAlgorithmName hashAlgorithm, DSASignatureFormat signatureFormat)
virtual bool TryHashData(ReadOnlySpan< byte > data, Span< byte > destination, HashAlgorithmName hashAlgorithm, out int bytesWritten)
bool TrySignHash(ReadOnlySpan< byte > hash, Span< byte > destination, DSASignatureFormat signatureFormat, out int bytesWritten)
bool VerifyData(ReadOnlySpan< byte > data, ReadOnlySpan< byte > signature, HashAlgorithmName hashAlgorithm, DSASignatureFormat signatureFormat)
virtual ECParameters ExportParameters(bool includePrivateParameters)
bool VerifyData(byte[] data, int offset, int count, byte[] signature, HashAlgorithmName hashAlgorithm, DSASignatureFormat signatureFormat)
virtual bool VerifyDataCore(ReadOnlySpan< byte > data, ReadOnlySpan< byte > signature, HashAlgorithmName hashAlgorithm, DSASignatureFormat signatureFormat)
virtual byte[] SignDataCore(ReadOnlySpan< byte > data, HashAlgorithmName hashAlgorithm, DSASignatureFormat signatureFormat)
bool VerifyData(Stream data, byte[] signature, HashAlgorithmName hashAlgorithm)
unsafe override void ImportEncryptedPkcs8PrivateKey(ReadOnlySpan< char > password, ReadOnlySpan< byte > source, out int bytesRead)
virtual byte[] SignData(byte[] data, int offset, int count, HashAlgorithmName hashAlgorithm)
virtual bool VerifyDataCore(Stream data, ReadOnlySpan< byte > signature, HashAlgorithmName hashAlgorithm, DSASignatureFormat signatureFormat)
virtual bool VerifyHashCore(ReadOnlySpan< byte > hash, ReadOnlySpan< byte > signature, DSASignatureFormat signatureFormat)
bool VerifyData(Stream data, byte[] signature, HashAlgorithmName hashAlgorithm, DSASignatureFormat signatureFormat)
int GetMaxSignatureSize(DSASignatureFormat signatureFormat)
static new ECDsa Create()
unsafe override bool TryExportEncryptedPkcs8PrivateKey(ReadOnlySpan< char > password, PbeParameters pbeParameters, Span< byte > destination, out int bytesWritten)
override void ImportSubjectPublicKeyInfo(ReadOnlySpan< byte > source, out int bytesRead)
bool VerifyHash(byte[] hash, byte[] signature, DSASignatureFormat signatureFormat)
override string ToXmlString(bool includePrivateParameters)
bool VerifyHash(ReadOnlySpan< byte > hash, ReadOnlySpan< byte > signature, DSASignatureFormat signatureFormat)
static void ValidatePbeParameters(PbeParameters pbeParameters, ReadOnlySpan< char > password, ReadOnlySpan< byte > passwordBytes)
void CopyTo(Span< T > destination)
Span< T > Slice(int start)