12 private int _dwKeySize;
16 private bool _randomKeyContainer;
19 private SafeProvHandle _safeProvHandle;
22 private SafeKeyHandle _safeKeyHandle;
34 [SecuritySafeCritical]
38 byte[] array = Utils._GetKeyParameter(_safeKeyHandle, 2u);
48 [SecuritySafeCritical]
60 [SecuritySafeCritical]
64 byte[] array = Utils._GetKeyParameter(_safeKeyHandle, 1u);
65 _dwKeySize = (array[0] | (array[1] << 8) | (array[2] << 16) | (array[3] << 24));
98 [SecuritySafeCritical]
101 if (_safeProvHandle ==
null)
105 if (_safeProvHandle ==
null)
107 _safeProvHandle = Utils.CreateProvHandle(_parameters, _randomKeyContainer);
111 return Utils.GetPersistKeyInCsp(_safeProvHandle);
113 [SecuritySafeCritical]
117 if (value != persistKeyInCsp)
130 keyContainerPermission.
Demand();
131 Utils.SetPersistKeyInCsp(_safeProvHandle, value);
138 : this(0, new
CspParameters(13, null, null, s_UseMachineKeyStore))
145 : this(dwKeySize, new
CspParameters(13, null, null, s_UseMachineKeyStore))
152 : this(0, parameters)
162 [SecuritySafeCritical]
169 _parameters = Utils.SaveCspParameters(CspAlgorithmType.Dss, parameters, s_UseMachineKeyStore, ref _randomKeyContainer);
174 _dwKeySize = dwKeySize;
176 if (!_randomKeyContainer ||
Environment.GetCompatibilityFlag(CompatibilityFlag.EagerlyGenerateRandomAsymmKeys))
183 private void GetKeyPair()
185 if (_safeKeyHandle ==
null)
189 if (_safeKeyHandle ==
null)
191 Utils.GetKeyPairHelper(CspAlgorithmType.Dss, _parameters, _randomKeyContainer, _dwKeySize, ref _safeProvHandle, ref _safeKeyHandle);
197 [SecuritySafeCritical]
198 protected override void Dispose(
bool disposing)
200 base.Dispose(disposing);
201 if (_safeKeyHandle !=
null && !_safeKeyHandle.IsClosed)
203 _safeKeyHandle.Dispose();
205 if (_safeProvHandle !=
null && !_safeProvHandle.IsClosed)
207 _safeProvHandle.Dispose();
216 [SecuritySafeCritical]
220 if (includePrivateParameters)
225 keyContainerPermission.
Demand();
227 DSACspObject dSACspObject =
new DSACspObject();
228 int blobType = includePrivateParameters ? 7 : 6;
229 Utils._ExportKey(_safeKeyHandle, blobType, dSACspObject);
230 return DSAObjectToStruct(dSACspObject);
237 [SecuritySafeCritical]
242 return Utils.ExportCspBlobHelper(includePrivateParameters, _parameters, _safeKeyHandle);
248 [SecuritySafeCritical]
251 DSACspObject cspObject = DSAStructToObject(parameters);
252 if (_safeKeyHandle !=
null && !_safeKeyHandle.IsClosed)
254 _safeKeyHandle.Dispose();
256 _safeKeyHandle = SafeKeyHandle.InvalidHandle;
257 if (IsPublic(parameters))
259 Utils._ImportKey(Utils.StaticDssProvHandle, 8704,
CspProviderFlags.NoFlags, cspObject, ref _safeKeyHandle);
265 keyContainerPermission.
Demand();
266 if (_safeProvHandle ==
null)
268 _safeProvHandle = Utils.CreateProvHandle(_parameters, _randomKeyContainer);
270 Utils._ImportKey(_safeProvHandle, 8704, _parameters.
Flags, cspObject, ref _safeKeyHandle);
275 [SecuritySafeCritical]
279 Utils.ImportCspBlobHelper(CspAlgorithmType.Dss, keyBlob, IsPublic(keyBlob), ref _parameters, _randomKeyContainer, ref _safeProvHandle, ref _safeKeyHandle);
305 public byte[]
SignData(
byte[] buffer,
int offset,
int count)
307 byte[] rgbHash = _sha1.
ComputeHash(buffer, offset, count);
319 return VerifyHash(rgbHash,
null, rgbSignature);
337 return VerifyHash(rgbHash,
null, rgbSignature);
364 [SecuritySafeCritical]
375 int calgHash = X509Utils.NameOrOidToAlgId(str,
OidGroup.HashAlgorithm);
376 if (rgbHash.Length != _sha1.
HashSize / 8)
386 keyContainerPermission.
Demand();
388 return Utils.SignValue(_safeKeyHandle, _parameters.
KeyNumber, 8704, calgHash, rgbHash);
399 [SecuritySafeCritical]
400 public bool VerifyHash(
byte[] rgbHash,
string str,
byte[] rgbSignature)
406 if (rgbSignature ==
null)
410 int calgHash = X509Utils.NameOrOidToAlgId(str,
OidGroup.HashAlgorithm);
411 if (rgbHash.Length != _sha1.
HashSize / 8)
416 return Utils.VerifySign(_safeKeyHandle, 8704, calgHash, rgbHash, rgbSignature);
419 private static DSAParameters DSAObjectToStruct(DSACspObject dsaCspObject)
422 result.
P = dsaCspObject.P;
423 result.
Q = dsaCspObject.Q;
424 result.
G = dsaCspObject.G;
425 result.
Y = dsaCspObject.Y;
426 result.
J = dsaCspObject.J;
427 result.
X = dsaCspObject.X;
428 result.
Seed = dsaCspObject.Seed;
429 result.
Counter = dsaCspObject.Counter;
433 private static DSACspObject DSAStructToObject(DSAParameters dsaParams)
435 DSACspObject dSACspObject =
new DSACspObject();
436 dSACspObject.P = dsaParams.P;
437 dSACspObject.Q = dsaParams.Q;
438 dSACspObject.G = dsaParams.G;
439 dSACspObject.Y = dsaParams.Y;
440 dSACspObject.J = dsaParams.J;
441 dSACspObject.X = dsaParams.X;
442 dSACspObject.Seed = dsaParams.Seed;
443 dSACspObject.Counter = dsaParams.Counter;
447 private static bool IsPublic(DSAParameters dsaParams)
449 return dsaParams.X ==
null;
452 private static bool IsPublic(
byte[] keyBlob)
456 throw new ArgumentNullException(
"keyBlob");
462 if ((keyBlob[11] != 49 && keyBlob[11] != 51) || keyBlob[10] != 83 || keyBlob[9] != 83 || keyBlob[8] != 68)
The exception that is thrown when an error occurs during a cryptographic operation.
bool VerifyHash(byte[] rgbHash, string str, byte[] rgbSignature)
Verifies the specified signature data by comparing it to the signature computed for the specified has...
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
override byte [] HashData(byte[] data, int offset, int count, HashAlgorithmName hashAlgorithm)
When overridden in a derived class, computes the hash value of a specified portion of a byte array by...
static bool? UseMachineKeyStore
Gets or sets a value indicating whether the key should be persisted in the computer's key store inste...
byte [] J
Specifies the J parameter for the T:System.Security.Cryptography.DSA algorithm.
override byte [] HashData(Stream data, HashAlgorithmName hashAlgorithm)
When overridden in a derived class, computes the hash value of a specified binary stream by using a s...
int KeyNumber
Specifies whether an asymmetric key is created as a signature key or an exchange key.
string Name
Gets the underlying string representation of the algorithm name.
byte [] SignData(byte[] buffer, int offset, int count)
Signs a byte array from the specified start point to the specified end point.
byte [] P
Specifies the P parameter for the T:System.Security.Cryptography.DSA algorithm.
byte [] X
Specifies the X parameter for the T:System.Security.Cryptography.DSA algorithm.
The exception that is thrown when the value of an argument is outside the allowable range of values a...
byte [] Q
Specifies the Q parameter for the T:System.Security.Cryptography.DSA algorithm.
Specifies access rights for specific key containers. This class cannot be inherited.
CspProviderFlags
Specifies flags that modify the behavior of the cryptographic service providers (CSP).
bool PersistKeyInCsp
Gets or sets a value indicating whether the key should be persisted in the cryptographic service prov...
DSACryptoServiceProvider()
Initializes a new instance of the T:System.Security.Cryptography.DSACryptoServiceProvider class.
OidGroup
Identifies Windows cryptographic object identifier (OID) groups.
static HashAlgorithmName SHA1
Gets a hash algorithm name that represents "SHA1".
Controls the ability to access key containers. This class cannot be inherited.
override byte [] CreateSignature(byte[] rgbHash)
Creates the T:System.Security.Cryptography.DSA signature for the specified data.
Defines methods that allow an T:System.Security.Cryptography.AsymmetricAlgorithm class to enumerate k...
override void ImportParameters(DSAParameters parameters)
Imports the specified T:System.Security.Cryptography.DSAParameters.
DSACryptoServiceProvider(int dwKeySize)
Initializes a new instance of the T:System.Security.Cryptography.DSACryptoServiceProvider class with ...
Specifies the name of a cryptographic hash algorithm.
KeySizes [] LegalKeySizesValue
Specifies the key sizes that are supported by the asymmetric algorithm.
byte [] SignData(Stream inputStream)
Computes the hash value of the specified input stream and signs the resulting hash value.
byte [] Seed
Specifies the seed for the T:System.Security.Cryptography.DSA algorithm.
Represents the abstract base class from which all implementations of the Digital Signature Algorithm ...
Provides information about, and means to manipulate, the current environment and platform....
override int KeySize
Gets the size of the key used by the asymmetric algorithm in bits.
byte [] ExportCspBlob(bool includePrivateParameters)
Exports a blob containing the key information associated with a T:System.Security....
byte [] SignHash(byte[] rgbHash, string str)
Computes the signature for the specified hash value by encrypting it with the private key.
byte [] Y
Specifies the Y parameter for the T:System.Security.Cryptography.DSA algorithm.
bool VerifyData(byte[] rgbData, byte[] rgbSignature)
Verifies the specified signature data by comparing it to the signature computed for the specified dat...
int Add(KeyContainerPermissionAccessEntry accessEntry)
Adds a T:System.Security.Permissions.KeyContainerPermissionAccessEntry object to the collection.
KeyContainerPermissionAccessEntryCollection AccessEntries
Gets the collection of T:System.Security.Permissions.KeyContainerPermissionAccessEntry objects associ...
override DSAParameters ExportParameters(bool includePrivateParameters)
Exports the T:System.Security.Cryptography.DSAParameters.
byte [] SignData(byte[] buffer)
Computes the hash value of the specified byte array and signs the resulting hash value.
Contains parameters that are passed to the cryptographic service provider (CSP) that performs cryptog...
KeyContainerPermissionFlags
Specifies the type of key container access allowed.
override string SignatureAlgorithm
Gets the name of the signature algorithm.
Determines the set of valid key sizes for the symmetric cryptographic algorithms.
byte [] G
Specifies the G parameter for the T:System.Security.Cryptography.DSA algorithm.
void ImportCspBlob(byte[] keyBlob)
Imports a blob that represents DSA key information.
void Demand()
Forces a T:System.Security.SecurityException at run time if all callers higher in the call stack have...
Defines a wrapper object to access the cryptographic service provider (CSP) implementation of the T:S...
bool PublicOnly
Gets a value that indicates whether the T:System.Security.Cryptography.DSACryptoServiceProvider objec...
DSACryptoServiceProvider(int dwKeySize, CspParameters parameters)
Initializes a new instance of the T:System.Security.Cryptography.DSACryptoServiceProvider class with ...
Provides additional information about a cryptographic key pair. This class cannot be inherited.
override string KeyExchangeAlgorithm
Gets the name of the key exchange algorithm.
CspKeyContainerInfo CspKeyContainerInfo
Gets a T:System.Security.Cryptography.CspKeyContainerInfo object that describes additional informatio...
DSACryptoServiceProvider(CspParameters parameters)
Initializes a new instance of the T:System.Security.Cryptography.DSACryptoServiceProvider class with ...
virtual int HashSize
Gets the size, in bits, of the computed hash code.
int Counter
Specifies the counter for the T:System.Security.Cryptography.DSA algorithm.
override bool VerifySignature(byte[] rgbHash, byte[] rgbSignature)
Verifies the T:System.Security.Cryptography.DSA signature for the specified data.
override void Dispose(bool disposing)
Releases the unmanaged resources used by the T:System.Security.Cryptography.AsymmetricAlgorithm class...
CspProviderFlags Flags
Represents the flags for T:System.Security.Cryptography.CspParameters that modify the behavior of the...
bool RandomlyGenerated
Gets a value indicating whether a key container was randomly generated by a managed cryptography clas...
byte [] ComputeHash(Stream inputStream)
Computes the hash value for the specified T:System.IO.Stream object.
Contains the typical parameters for the T:System.Security.Cryptography.DSA algorithm.
Computes the T:System.Security.Cryptography.SHA1 hash value for the input data using the implementati...
Provides a generic view of a sequence of bytes. This is an abstract class.To browse the ....