Early Preview
This is currently very much a preview. Please feel free to try things out,
but don't be upset if anything is not yet working. Feedback is welcome over on our
GitHub Dicussions page.
class System.​Security.​Cryptography.​ECDsa
Assembly: System.Security.Cryptography
Inheritance: object → AsymmetricAlgorithm → ECAlgorithm → ECDsa
Provides an abstract base class that encapsulates the Elliptic Curve Digital Signature Algorithm (ECDSA).
Fields and Constants
protected
int
KeySizeValue
Represents the size, in bits, of the key modulus used by the asymmetric algorithm.
protected
KeySizes[]
LegalKeySizesValue
Specifies the key sizes that are supported by the asymmetric algorithm.
Properties
public
string
KeyExchangeAlgorithm
Gets the name of the key exchange algorithm.
public
string
SignatureAlgorithm
Gets the name of the signature algorithm.
public
int
KeySize
Gets or sets the size, in bits, of the key modulus used by the asymmetric algorithm.
public
KeySizes[]
LegalKeySizes
Gets the key sizes that are supported by the asymmetric algorithm.
Methods
public
void
FromXmlString​(string xmlString)
xmlString
The XML string to use to reconstruct the <see cref="T:System.Security.Cryptography.AsymmetricAlgorithm" /> object.
This method throws in all cases.
public
int
GetMaxSignatureSize​(DSASignatureFormat signatureFormat)
signatureFormat
The encoding format for a signature.
Returns The largest size, in bytes, for a signature produced by this key in the indicated format.
Gets the largest size, in bytes, for a signature produced by this key in the indicated format.
protected
byte[]
HashData​(byte[] data,
int offset,
int count,
HashAlgorithmName hashAlgorithm)
data
The data to be hashed.
offset
The index of the first byte in <paramref name="data" /> to be hashed.
count
The number of bytes to hash.
hashAlgorithm
The algorithm to use to hash the data.
Returns The hashed data.
When overridden in a derived class, computes the hash value of the specified portion of a byte array by using the specified hashing algorithm.
protected
byte[]
HashData​(IO.Stream data,
HashAlgorithmName hashAlgorithm)
data
The binary stream to hash.
hashAlgorithm
The algorithm to use to hash the data.
Returns The hashed data.
When overridden in a derived class, computes the hash value of the specified binary stream by using the specified hashing algorithm.
public
byte[]
SignData​(byte[] data,
int offset,
int count,
HashAlgorithmName hashAlgorithm)
data
The input data for which to compute the hash.
offset
The offset into the array at which to begin using data.
count
The number of bytes in the array to use as data.
hashAlgorithm
The hash algorithm to use to create the hash value.
Returns The ECDSA signature for the specified data.
Computes the hash value of a portion of the specified byte array using the specified hash algorithm and signs the resulting hash value.
public
byte[]
SignData​(byte[] data,
int offset,
int count,
HashAlgorithmName hashAlgorithm,
DSASignatureFormat signatureFormat)
data
The data to sign.
offset
The offset into <paramref name="data" /> at which to begin hashing.
count
The number of bytes to read from <paramref name="data" /> .
hashAlgorithm
The hash algorithm to use to create the hash value.
signatureFormat
The encoding format to use for the signature.
Returns The ECDSA signature for the specified data.
Computes the hash value of the specified data and signs it using the specified signature format.
public
byte[]
SignData​(byte[] data,
HashAlgorithmName hashAlgorithm)
data
The input data for which to compute the hash.
hashAlgorithm
The hash algorithm to use to create the hash value.
Returns The ECDSA signature for the specified data.
Computes the hash value of the specified byte array using the specified hash algorithm and signs the resulting hash value.
public
byte[]
SignData​(byte[] data,
HashAlgorithmName hashAlgorithm,
DSASignatureFormat signatureFormat)
data
The data to sign.
hashAlgorithm
The hash algorithm to use to create the hash value.
signatureFormat
The encoding format to use for the signature.
Returns The ECDSA signature for the specified data.
Computes the hash value of the specified data and signs it using the specified signature format.
public
byte[]
SignData​(IO.Stream data,
HashAlgorithmName hashAlgorithm)
data
The input stream for which to compute the hash.
hashAlgorithm
The hash algorithm to use to create the hash value.
Returns The ECDSA signature for the specified data.
Computes the hash value of the specified stream using the specified hash algorithm and signs the resulting hash value.
public
byte[]
SignData​(IO.Stream data,
HashAlgorithmName hashAlgorithm,
DSASignatureFormat signatureFormat)
data
The data to sign.
hashAlgorithm
The hash algorithm to use to create the hash value.
signatureFormat
The encoding format to use for the signature.
Returns The ECDSA signature for the specified data.
Computes the hash value of the specified data and signs it using the specified signature format.
public
byte[]
SignData​(ReadOnlySpan`1 data,
HashAlgorithmName hashAlgorithm,
DSASignatureFormat signatureFormat)
public
int
SignData​(ReadOnlySpan`1 data,
Span`1 destination,
HashAlgorithmName hashAlgorithm)
public
int
SignData​(ReadOnlySpan`1 data,
Span`1 destination,
HashAlgorithmName hashAlgorithm,
DSASignatureFormat signatureFormat)
protected
byte[]
SignDataCore​(IO.Stream data,
HashAlgorithmName hashAlgorithm,
DSASignatureFormat signatureFormat)
data
The data to sign.
hashAlgorithm
The hash algorithm to use to create the hash value.
signatureFormat
The encoding format to use for the signature.
Returns The ECDSA signature for the specified data.
Computes the hash value of the specified data and signs it using the specified signature format.
protected
byte[]
SignDataCore​(ReadOnlySpan`1 data,
HashAlgorithmName hashAlgorithm,
DSASignatureFormat signatureFormat)
public
byte[]
SignHash​(byte[] hash)
hash
The hash value of the data that is being signed.
Returns A digital signature for the specified hash value.
Generates a digital signature for the specified hash value.
public
byte[]
SignHash​(byte[] hash,
DSASignatureFormat signatureFormat)
hash
The hash value to sign.
signatureFormat
The encoding format to use for the signature.
Returns The ECDSA signature for the specified data.
Computes the ECDSA signature for the specified hash value in the indicated format.
public
int
SignHash​(ReadOnlySpan`1 hash,
Span`1 destination,
DSASignatureFormat signatureFormat)
protected
byte[]
SignHashCore​(ReadOnlySpan`1 hash,
DSASignatureFormat signatureFormat)
public
string
ToXmlString​(bool includePrivateParameters)
includePrivateParameters
<see langword="true" /> to include private parameters; otherwise, <see langword="false" /> .
Returns This method does not return a value.
This method throws in all cases.
protected
bool
TryHashData​(ReadOnlySpan`1 data,
Span`1 destination,
HashAlgorithmName hashAlgorithm,
Int32& bytesWritten)
public
bool
TrySignData​(ReadOnlySpan`1 data,
Span`1 destination,
HashAlgorithmName hashAlgorithm,
Int32& bytesWritten)
public
bool
TrySignData​(ReadOnlySpan`1 data,
Span`1 destination,
HashAlgorithmName hashAlgorithm,
DSASignatureFormat signatureFormat,
Int32& bytesWritten)
protected
bool
TrySignDataCore​(ReadOnlySpan`1 data,
Span`1 destination,
HashAlgorithmName hashAlgorithm,
DSASignatureFormat signatureFormat,
Int32& bytesWritten)
public
bool
TrySignHash​(ReadOnlySpan`1 hash,
Span`1 destination,
Int32& bytesWritten)
public
bool
TrySignHash​(ReadOnlySpan`1 hash,
Span`1 destination,
DSASignatureFormat signatureFormat,
Int32& bytesWritten)
protected
bool
TrySignHashCore​(ReadOnlySpan`1 hash,
Span`1 destination,
DSASignatureFormat signatureFormat,
Int32& bytesWritten)
public
bool
VerifyData​(byte[] data,
byte[] signature,
HashAlgorithmName hashAlgorithm)
data
The signed data.
signature
The signature data to be verified.
hashAlgorithm
The hash algorithm used to create the hash value of the data.
Returns <see langword="true" /> if the signature is valid; otherwise, <see langword="false" /> .
Verifies that a digital signature is appropriate for the current key and provided data with a specified hash algorithm.
public
bool
VerifyData​(byte[] data,
byte[] signature,
HashAlgorithmName hashAlgorithm,
DSASignatureFormat signatureFormat)
data
The signed data.
signature
The signature to verify.
hashAlgorithm
The hash algorithm used to hash the data for the verification process.
signatureFormat
The encoding format for <paramref name="signature" /> .
Returns <see langword="true" /> if the digital signature is valid for the provided data; otherwise, <see langword="false" /> .
Verifies that a digital signature is valid for the provided data.
public
bool
VerifyData​(byte[] data,
int offset,
int count,
byte[] signature,
HashAlgorithmName hashAlgorithm)
data
The signed data.
offset
The starting index at which to compute the hash.
count
The number of bytes to hash.
signature
The signature data to be verified.
hashAlgorithm
The hash algorithm used to create the hash value of the data.
Returns <see langword="true" /> if the signature is valid; otherwise, <see langword="false" /> .
Verifies that a digital signature is appropriate for the current key and provided portion of data with a specified hash algorithm.
public
bool
VerifyData​(byte[] data,
int offset,
int count,
byte[] signature,
HashAlgorithmName hashAlgorithm,
DSASignatureFormat signatureFormat)
data
An array that contains the signed data.
offset
The starting index of the signed portion of <paramref name="data" /> .
count
The number of bytes in <paramref name="data" /> that were signed.
signature
The signature to verify.
hashAlgorithm
The hash algorithm used to hash the data for the verification process.
signatureFormat
The encoding format for <paramref name="signature" /> .
Returns <see langword="true" /> if the digital signature is valid for the provided data; otherwise, <see langword="false" /> .
Verifies that a digital signature is valid for the provided data.
public
bool
VerifyData​(IO.Stream data,
byte[] signature,
HashAlgorithmName hashAlgorithm)
data
The signed data.
signature
The signature data to be verified.
hashAlgorithm
The hash algorithm used to create the hash value of the data.
Returns <see langword="true" /> if the signature is valid; otherwise, <see langword="false" /> .
Verifies that a digital signature is appropriate for the current key and provided data with a specified hash algorithm.
public
bool
VerifyData​(IO.Stream data,
byte[] signature,
HashAlgorithmName hashAlgorithm,
DSASignatureFormat signatureFormat)
data
The signed data.
signature
The signature to verify.
hashAlgorithm
The hash algorithm used to hash the data for the verification process.
signatureFormat
The encoding format for <paramref name="signature" /> .
Returns <see langword="true" /> if the digital signature is valid for the provided data; otherwise, <see langword="false" /> .
Verifies that a digital signature is valid for the provided data.
public
bool
VerifyData​(ReadOnlySpan`1 data,
ReadOnlySpan`1 signature,
HashAlgorithmName hashAlgorithm)
public
bool
VerifyData​(ReadOnlySpan`1 data,
ReadOnlySpan`1 signature,
HashAlgorithmName hashAlgorithm,
DSASignatureFormat signatureFormat)
protected
bool
VerifyDataCore​(IO.Stream data,
ReadOnlySpan`1 signature,
HashAlgorithmName hashAlgorithm,
DSASignatureFormat signatureFormat)
protected
bool
VerifyDataCore​(ReadOnlySpan`1 data,
ReadOnlySpan`1 signature,
HashAlgorithmName hashAlgorithm,
DSASignatureFormat signatureFormat)
public
bool
VerifyHash​(byte[] hash,
byte[] signature)
hash
The hash value of the data to be verified.
signature
The digital signature of the data to be verified against the hash value.
Returns <see langword="true" /> if the signature is valid; otherwise, <see langword="false" /> .
Verifies that a digital signature is appropriate for the current key and provided data hash.
public
bool
VerifyHash​(byte[] hash,
byte[] signature,
DSASignatureFormat signatureFormat)
hash
The signed hash.
signature
The signature to verify.
signatureFormat
The encoding format for <paramref name="signature" /> .
Returns <see langword="true" /> if the digital signature is valid for the provided data; otherwise, <see langword="false" /> .
Verifies that a digital signature is valid for the provided hash.
public
bool
VerifyHash​(ReadOnlySpan`1 hash,
ReadOnlySpan`1 signature,
DSASignatureFormat signatureFormat)
protected
bool
VerifyHashCore​(ReadOnlySpan`1 hash,
ReadOnlySpan`1 signature,
DSASignatureFormat signatureFormat)
public
byte[]
ExportECPrivateKey​()
Inherited from ECAlgorithm
Returns A byte array containing the ECPrivateKey representation of this key.
Exports the current key in the ECPrivateKey format.
public
string
ExportECPrivateKeyPem​()
Inherited from ECAlgorithm
Returns A string containing the PEM-encoded ECPrivateKey.
Exports the current key in the ECPrivateKey format, PEM encoded.
public
ECParameters
ExportExplicitParameters​(bool includePrivateParameters)
Inherited from ECAlgorithm
includePrivateParameters
<see langword="true" /> to include private parameters, otherwise, <see langword="false" /> .
Returns The exported explicit parameters.
When overridden in a derived class, exports the explicit <see cref="T:System.Security.Cryptography.ECParameters" /> for an ECCurve.
public
ECParameters
ExportParameters​(bool includePrivateParameters)
Inherited from ECAlgorithm
includePrivateParameters
<see langword="true" /> to include private parameters, otherwise, <see langword="false" /> .
Returns The exported parameters.
When overridden in a derived class, exports the named or explicit <see cref="T:System.Security.Cryptography.ECParameters" /> for an ECCurve.
If the curve has a name, the Curve property will contain named curve parameters otherwise it will contain explicit parameters.
public
void
GenerateKey​(ECCurve curve)
Inherited from ECAlgorithm
curve
The curve to use.
When overridden in a derived class, generates a new public/private keypair for the specified curve.
public
void
ImportECPrivateKey​(ReadOnlySpan`1 source,
Int32& bytesRead)
Inherited from ECAlgorithm
public
void
ImportEncryptedPkcs8PrivateKey​(ReadOnlySpan`1 passwordBytes,
ReadOnlySpan`1 source,
Int32& bytesRead)
Inherited from ECAlgorithm
public
void
ImportEncryptedPkcs8PrivateKey​(ReadOnlySpan`1 password,
ReadOnlySpan`1 source,
Int32& bytesRead)
Inherited from ECAlgorithm
public
void
ImportFromEncryptedPem​(ReadOnlySpan`1 input,
ReadOnlySpan`1 passwordBytes)
Inherited from ECAlgorithm
public
void
ImportFromEncryptedPem​(ReadOnlySpan`1 input,
ReadOnlySpan`1 password)
Inherited from ECAlgorithm
public
void
ImportParameters​(ECParameters parameters)
Inherited from ECAlgorithm
parameters
The curve parameters.
When overridden in a derived class, imports the specified <see cref="T:System.Security.Cryptography.ECParameters" /> .
public
void
ImportPkcs8PrivateKey​(ReadOnlySpan`1 source,
Int32& bytesRead)
Inherited from ECAlgorithm
public
void
ImportSubjectPublicKeyInfo​(ReadOnlySpan`1 source,
Int32& bytesRead)
Inherited from ECAlgorithm
public
bool
TryExportECPrivateKey​(Span`1 destination,
Int32& bytesWritten)
Inherited from ECAlgorithm
public
bool
TryExportECPrivateKeyPem​(Span`1 destination,
Int32& charsWritten)
Inherited from ECAlgorithm
public
bool
TryExportEncryptedPkcs8PrivateKey​(ReadOnlySpan`1 passwordBytes,
PbeParameters pbeParameters,
Span`1 destination,
Int32& bytesWritten)
Inherited from ECAlgorithm
public
bool
TryExportEncryptedPkcs8PrivateKey​(ReadOnlySpan`1 password,
PbeParameters pbeParameters,
Span`1 destination,
Int32& bytesWritten)
Inherited from ECAlgorithm
public
bool
TryExportPkcs8PrivateKey​(Span`1 destination,
Int32& bytesWritten)
Inherited from ECAlgorithm
public
bool
TryExportSubjectPublicKeyInfo​(Span`1 destination,
Int32& bytesWritten)
Inherited from ECAlgorithm
Releases all resources used by the <see cref="T:System.Security.Cryptography.AsymmetricAlgorithm" /> class.
Releases all resources used by the current instance of the <see cref="T:System.Security.Cryptography.AsymmetricAlgorithm" /> class.
protected
void
Dispose​(bool disposing)
Inherited from AsymmetricAlgorithm
disposing
<see langword="true" /> to release both managed and unmanaged resources; <see langword="false" /> to release only unmanaged resources.
Releases the unmanaged resources used by the <see cref="T:System.Security.Cryptography.AsymmetricAlgorithm" /> class and optionally releases the managed resources.
public
byte[]
ExportEncryptedPkcs8PrivateKey​(ReadOnlySpan`1 passwordBytes,
PbeParameters pbeParameters)
Inherited from AsymmetricAlgorithm
public
byte[]
ExportEncryptedPkcs8PrivateKey​(ReadOnlySpan`1 password,
PbeParameters pbeParameters)
Inherited from AsymmetricAlgorithm
public
string
ExportEncryptedPkcs8PrivateKeyPem​(ReadOnlySpan`1 passwordBytes,
PbeParameters pbeParameters)
Inherited from AsymmetricAlgorithm
public
string
ExportEncryptedPkcs8PrivateKeyPem​(ReadOnlySpan`1 password,
PbeParameters pbeParameters)
Inherited from AsymmetricAlgorithm
public
byte[]
ExportPkcs8PrivateKey​()
Inherited from AsymmetricAlgorithm
Returns A byte array containing the PKCS#8 PrivateKeyInfo representation of this key.
Exports the current key in the PKCS#8 PrivateKeyInfo format.
public
string
ExportPkcs8PrivateKeyPem​()
Inherited from AsymmetricAlgorithm
Returns A string containing the PEM-encoded PKCS#8 PrivateKeyInfo.
Exports the current key in the PKCS#8 PrivateKeyInfo format, PEM encoded.
public
byte[]
ExportSubjectPublicKeyInfo​()
Inherited from AsymmetricAlgorithm
Returns A byte array containing the X.509 SubjectPublicKeyInfo representation of the public-key portion of this key.
Exports the public-key portion of the current key in the X.509 SubjectPublicKeyInfo format.
public
string
ExportSubjectPublicKeyInfoPem​()
Inherited from AsymmetricAlgorithm
Returns A string containing the PEM-encoded X.509 SubjectPublicKeyInfo.
Exports the public-key portion of the current key in the X.509 SubjectPublicKeyInfo format, PEM encoded.
public
bool
TryExportEncryptedPkcs8PrivateKeyPem​(ReadOnlySpan`1 passwordBytes,
PbeParameters pbeParameters,
Span`1 destination,
Int32& charsWritten)
Inherited from AsymmetricAlgorithm
public
bool
TryExportEncryptedPkcs8PrivateKeyPem​(ReadOnlySpan`1 password,
PbeParameters pbeParameters,
Span`1 destination,
Int32& charsWritten)
Inherited from AsymmetricAlgorithm
public
bool
TryExportPkcs8PrivateKeyPem​(Span`1 destination,
Int32& charsWritten)
Inherited from AsymmetricAlgorithm
public
bool
TryExportSubjectPublicKeyInfoPem​(Span`1 destination,
Int32& charsWritten)
Inherited from AsymmetricAlgorithm
public
bool
Equals​(object obj)
Inherited from object
protected
void
Finalize​()
Inherited from object
public
int
GetHashCode​()
Inherited from object
protected
object
MemberwiseClone​()
Inherited from object
public
string
ToString​()
Inherited from object