using System;
using System.Globalization;
using System.IO;
using System.Runtime.InteropServices;
using Mono.Security.Cryptography;
namespace System.Security.Cryptography
{
/// Defines a wrapper object to access the cryptographic service provider (CSP) implementation of the algorithm. This class cannot be inherited.
// Token: 0x020004FA RID: 1274
[ComVisible(true)]
public sealed class DSACryptoServiceProvider : DSA, ICspAsymmetricAlgorithm
{
/// Initializes a new instance of the class.
// Token: 0x06002F14 RID: 12052 RVA: 0x00097BD8 File Offset: 0x00095DD8
public DSACryptoServiceProvider()
: this(1024, null)
{
}
/// Initializes a new instance of the class with the specified parameters for the cryptographic service provider (CSP).
/// The parameters for the CSP.
// Token: 0x06002F15 RID: 12053 RVA: 0x00097BE8 File Offset: 0x00095DE8
public DSACryptoServiceProvider(CspParameters parameters)
: this(1024, parameters)
{
}
/// Initializes a new instance of the class with the specified key size.
/// The size of the key for the asymmetric algorithm in bits.
// Token: 0x06002F16 RID: 12054 RVA: 0x00097BF8 File Offset: 0x00095DF8
public DSACryptoServiceProvider(int dwKeySize)
: this(dwKeySize, null)
{
}
/// Initializes a new instance of the class with the specified key size and parameters for the cryptographic service provider (CSP).
/// The size of the key for the cryptographic algorithm in bits.
/// The parameters for the CSP.
/// The CSP cannot be acquired.-or- The key cannot be created.
///
/// is out of range.
// Token: 0x06002F17 RID: 12055 RVA: 0x00097C04 File Offset: 0x00095E04
public DSACryptoServiceProvider(int dwKeySize, CspParameters parameters)
{
this.LegalKeySizesValue = new KeySizes[1];
this.LegalKeySizesValue[0] = new KeySizes(512, 1024, 64);
this.KeySize = dwKeySize;
this.dsa = new DSAManaged(dwKeySize);
this.dsa.KeyGenerated += this.OnKeyGenerated;
this.persistKey = parameters != null;
if (parameters == null)
{
parameters = new CspParameters(13);
if (DSACryptoServiceProvider.useMachineKeyStore)
{
parameters.Flags |= CspProviderFlags.UseMachineKeyStore;
}
this.store = new KeyPairPersistence(parameters);
}
else
{
this.store = new KeyPairPersistence(parameters);
this.store.Load();
if (this.store.KeyValue != null)
{
this.persisted = true;
this.FromXmlString(this.store.KeyValue);
}
}
}
// Token: 0x06002F19 RID: 12057 RVA: 0x00097CF8 File Offset: 0x00095EF8
~DSACryptoServiceProvider()
{
this.Dispose(false);
}
/// Gets the name of the key exchange algorithm.
/// The name of the key exchange algorithm.
// Token: 0x1700094C RID: 2380
// (get) Token: 0x06002F1A RID: 12058 RVA: 0x00097D34 File Offset: 0x00095F34
public override string KeyExchangeAlgorithm
{
get
{
return null;
}
}
/// Gets the size of the key used by the asymmetric algorithm in bits.
/// The size of the key used by the asymmetric algorithm.
// Token: 0x1700094D RID: 2381
// (get) Token: 0x06002F1B RID: 12059 RVA: 0x00097D38 File Offset: 0x00095F38
public override int KeySize
{
get
{
return this.dsa.KeySize;
}
}
/// Gets or sets a value indicating whether the key should be persisted in the cryptographic service provider (CSP).
/// true if the key should be persisted in the CSP; otherwise, false.
// Token: 0x1700094E RID: 2382
// (get) Token: 0x06002F1C RID: 12060 RVA: 0x00097D48 File Offset: 0x00095F48
// (set) Token: 0x06002F1D RID: 12061 RVA: 0x00097D50 File Offset: 0x00095F50
public bool PersistKeyInCsp
{
get
{
return this.persistKey;
}
set
{
this.persistKey = value;
}
}
/// Gets a value that indicates whether the object contains only a public key.
/// true if the object contains only a public key; otherwise, false.
// Token: 0x1700094F RID: 2383
// (get) Token: 0x06002F1E RID: 12062 RVA: 0x00097D5C File Offset: 0x00095F5C
[ComVisible(false)]
public bool PublicOnly
{
get
{
return this.dsa.PublicOnly;
}
}
/// Gets the name of the signature algorithm.
/// The name of the signature algorithm.
// Token: 0x17000950 RID: 2384
// (get) Token: 0x06002F1F RID: 12063 RVA: 0x00097D6C File Offset: 0x00095F6C
public override string SignatureAlgorithm
{
get
{
return "http://www.w3.org/2000/09/xmldsig#dsa-sha1";
}
}
/// Gets or sets a value indicating whether the key should be persisted in the computer's key store instead of the user profile store.
/// true if the key should be persisted in the computer key store; otherwise, false.
// Token: 0x17000951 RID: 2385
// (get) Token: 0x06002F20 RID: 12064 RVA: 0x00097D74 File Offset: 0x00095F74
// (set) Token: 0x06002F21 RID: 12065 RVA: 0x00097D7C File Offset: 0x00095F7C
public static bool UseMachineKeyStore
{
get
{
return DSACryptoServiceProvider.useMachineKeyStore;
}
set
{
DSACryptoServiceProvider.useMachineKeyStore = value;
}
}
/// Exports the .
/// The parameters for .
/// true to include private parameters; otherwise, false.
/// The key cannot be exported.
///
///
///
// Token: 0x06002F22 RID: 12066 RVA: 0x00097D84 File Offset: 0x00095F84
public override DSAParameters ExportParameters(bool includePrivateParameters)
{
if (includePrivateParameters && !this.privateKeyExportable)
{
throw new CryptographicException(Locale.GetText("Cannot export private key"));
}
return this.dsa.ExportParameters(includePrivateParameters);
}
/// Imports the specified .
/// The parameters for .
/// The cryptographic service provider (CSP) cannot be acquired.-or- The parameter has missing fields.
///
///
///
// Token: 0x06002F23 RID: 12067 RVA: 0x00097DB4 File Offset: 0x00095FB4
public override void ImportParameters(DSAParameters parameters)
{
this.dsa.ImportParameters(parameters);
}
/// Creates the signature for the specified data.
/// The digital signature for the specified data.
/// The data to be signed.
///
///
///
// Token: 0x06002F24 RID: 12068 RVA: 0x00097DC4 File Offset: 0x00095FC4
public override byte[] CreateSignature(byte[] rgbHash)
{
return this.dsa.CreateSignature(rgbHash);
}
/// Computes the hash value of the specified byte array and signs the resulting hash value.
/// The signature for the specified data.
/// The input data for which to compute the hash.
///
///
///
// Token: 0x06002F25 RID: 12069 RVA: 0x00097DD4 File Offset: 0x00095FD4
public byte[] SignData(byte[] buffer)
{
HashAlgorithm hashAlgorithm = SHA1.Create();
byte[] array = hashAlgorithm.ComputeHash(buffer);
return this.dsa.CreateSignature(array);
}
/// Signs a byte array from the specified start point to the specified end point.
/// The signature for the specified data.
/// The input data to sign.
/// The offset into the array from which to begin using data.
/// The number of bytes in the array to use as data.
///
///
///
// Token: 0x06002F26 RID: 12070 RVA: 0x00097DFC File Offset: 0x00095FFC
public byte[] SignData(byte[] buffer, int offset, int count)
{
HashAlgorithm hashAlgorithm = SHA1.Create();
byte[] array = hashAlgorithm.ComputeHash(buffer, offset, count);
return this.dsa.CreateSignature(array);
}
/// Computes the hash value of the specified input stream and signs the resulting hash value.
/// The signature for the specified data.
/// The input data for which to compute the hash.
///
///
///
// Token: 0x06002F27 RID: 12071 RVA: 0x00097E28 File Offset: 0x00096028
public byte[] SignData(Stream inputStream)
{
HashAlgorithm hashAlgorithm = SHA1.Create();
byte[] array = hashAlgorithm.ComputeHash(inputStream);
return this.dsa.CreateSignature(array);
}
/// Computes the signature for the specified hash value by encrypting it with the private key.
/// The signature for the specified hash value.
/// The hash value of the data to be signed.
/// The name of the hash algorithm used to create the hash value of the data.
/// The parameter is null.
/// The cryptographic service provider (CSP) cannot be acquired.-or- There is no private key.
///
///
///
// Token: 0x06002F28 RID: 12072 RVA: 0x00097E50 File Offset: 0x00096050
public byte[] SignHash(byte[] rgbHash, string str)
{
if (string.Compare(str, "SHA1", true, CultureInfo.InvariantCulture) != 0)
{
throw new CryptographicException(Locale.GetText("Only SHA1 is supported."));
}
return this.dsa.CreateSignature(rgbHash);
}
/// Verifies the specified data using the specified signature.
/// true if the signature verifies the data; otherwise, false.
/// The data that was signed.
/// The signature data to verify.
///
///
///
// Token: 0x06002F29 RID: 12073 RVA: 0x00097E90 File Offset: 0x00096090
public bool VerifyData(byte[] rgbData, byte[] rgbSignature)
{
HashAlgorithm hashAlgorithm = SHA1.Create();
byte[] array = hashAlgorithm.ComputeHash(rgbData);
return this.dsa.VerifySignature(array, rgbSignature);
}
/// Verifies the specified hash data using the specified signature.
/// true if the signature verifies the hash; otherwise, false.
/// The hash value of the data to be signed.
/// The name of the hash algorithm used to create the hash value of the data.
/// The signature data to verify.
/// The parameter is null.-or- The parameter is null.
/// The cryptographic service provider (CSP) cannot be acquired.-or- The signature cannot be verified.
///
///
///
// Token: 0x06002F2A RID: 12074 RVA: 0x00097EB8 File Offset: 0x000960B8
public bool VerifyHash(byte[] rgbHash, string str, byte[] rgbSignature)
{
if (str == null)
{
str = "SHA1";
}
if (string.Compare(str, "SHA1", true, CultureInfo.InvariantCulture) != 0)
{
throw new CryptographicException(Locale.GetText("Only SHA1 is supported."));
}
return this.dsa.VerifySignature(rgbHash, rgbSignature);
}
/// Verifies the signature for the specified data.
/// true if matches the signature that is computed using the specified hash algorithm and key on ; otherwise, false.
/// The data signed with .
/// The signature to verify for .
///
///
///
// Token: 0x06002F2B RID: 12075 RVA: 0x00097F08 File Offset: 0x00096108
public override bool VerifySignature(byte[] rgbHash, byte[] rgbSignature)
{
return this.dsa.VerifySignature(rgbHash, rgbSignature);
}
/// Releases the unmanaged resources used by the and optionally releases the managed resources.
/// true to release both managed and unmanaged resources; false to release only unmanaged resources.
// Token: 0x06002F2C RID: 12076 RVA: 0x00097F18 File Offset: 0x00096118
protected override void Dispose(bool disposing)
{
if (!this.m_disposed)
{
if (this.persisted && !this.persistKey)
{
this.store.Remove();
}
if (this.dsa != null)
{
this.dsa.Clear();
}
this.m_disposed = true;
}
}
// Token: 0x06002F2D RID: 12077 RVA: 0x00097F70 File Offset: 0x00096170
private void OnKeyGenerated(object sender, EventArgs e)
{
if (this.persistKey && !this.persisted)
{
this.store.KeyValue = this.ToXmlString(!this.dsa.PublicOnly);
this.store.Save();
this.persisted = true;
}
}
/// Gets a object that describes additional information about a cryptographic key pair.
/// A object that describes additional information about a cryptographic key pair.
// Token: 0x17000952 RID: 2386
// (get) Token: 0x06002F2E RID: 12078 RVA: 0x00097FC4 File Offset: 0x000961C4
[ComVisible(false)]
[MonoTODO("call into KeyPairPersistence to get details")]
public CspKeyContainerInfo CspKeyContainerInfo
{
get
{
return null;
}
}
/// Exports a blob containing the key information associated with a object.
/// A byte array containing the key information associated with a object.
/// true to include the private key; otherwise, false.
///
///
///
// Token: 0x06002F2F RID: 12079 RVA: 0x00097FC8 File Offset: 0x000961C8
[ComVisible(false)]
public byte[] ExportCspBlob(bool includePrivateParameters)
{
byte[] array;
if (includePrivateParameters)
{
array = CryptoConvert.ToCapiPrivateKeyBlob(this);
}
else
{
array = CryptoConvert.ToCapiPublicKeyBlob(this);
}
return array;
}
/// Imports a blob that represents DSA key information.
/// A byte array that represents a DSA key blob.
///
///
///
///
// Token: 0x06002F30 RID: 12080 RVA: 0x00097FF4 File Offset: 0x000961F4
[ComVisible(false)]
public void ImportCspBlob(byte[] keyBlob)
{
if (keyBlob == null)
{
throw new ArgumentNullException("keyBlob");
}
DSA dsa = CryptoConvert.FromCapiKeyBlobDSA(keyBlob);
if (dsa is DSACryptoServiceProvider)
{
DSAParameters dsaparameters = dsa.ExportParameters(!(dsa as DSACryptoServiceProvider).PublicOnly);
this.ImportParameters(dsaparameters);
}
else
{
try
{
DSAParameters dsaparameters2 = dsa.ExportParameters(true);
this.ImportParameters(dsaparameters2);
}
catch
{
DSAParameters dsaparameters3 = dsa.ExportParameters(false);
this.ImportParameters(dsaparameters3);
}
}
}
// Token: 0x04001336 RID: 4918
private const int PROV_DSS_DH = 13;
// Token: 0x04001337 RID: 4919
private KeyPairPersistence store;
// Token: 0x04001338 RID: 4920
private bool persistKey;
// Token: 0x04001339 RID: 4921
private bool persisted;
// Token: 0x0400133A RID: 4922
private bool privateKeyExportable = true;
// Token: 0x0400133B RID: 4923
private bool m_disposed;
// Token: 0x0400133C RID: 4924
private DSAManaged dsa;
// Token: 0x0400133D RID: 4925
private static bool useMachineKeyStore;
}
}