void Common(int dwKeySize, bool parameters) { LegalKeySizesValue = new KeySizes [1]; LegalKeySizesValue [0] = new KeySizes(512, 1024, 64); // will throw an exception is key size isn't supported KeySize = dwKeySize; dsa = new DSAManaged(dwKeySize); dsa.KeyGenerated += new DSAManaged.KeyGeneratedEventHandler(OnKeyGenerated); persistKey = parameters; if (parameters) { return; } var p = new CspParameters(PROV_DSS_DH); if (useMachineKeyStore) { p.Flags |= CspProviderFlags.UseMachineKeyStore; } store = new KeyPairPersistence(p); // no need to load - it cannot exists }
public DSACryptoServiceProvider(int dwKeySize, CspParameters parameters) { LegalKeySizesValue = new KeySizes [1]; LegalKeySizesValue [0] = new KeySizes(512, 1024, 64); // will throw an exception is key size isn't supported KeySize = dwKeySize; dsa = new DSAManaged(dwKeySize); dsa.KeyGenerated += new DSAManaged.KeyGeneratedEventHandler(OnKeyGenerated); persistKey = (parameters != null); if (parameters == null) { parameters = new CspParameters(PROV_DSS_DH); if (useMachineKeyStore) { parameters.Flags |= CspProviderFlags.UseMachineKeyStore; } store = new KeyPairPersistence(parameters); // no need to load - it cannot exists } else { store = new KeyPairPersistence(parameters); store.Load(); if (store.KeyValue != null) { persisted = true; this.FromXmlString(store.KeyValue); } } }
/// <summary>Initializes a new instance of the <see cref="T:System.Security.Cryptography.DSACryptoServiceProvider" /> class with the specified key size and parameters for the cryptographic service provider (CSP).</summary> /// <param name="dwKeySize">The size of the key for the cryptographic algorithm in bits. </param> /// <param name="parameters">The parameters for the CSP. </param> /// <exception cref="T:System.Security.Cryptography.CryptographicException">The CSP cannot be acquired.-or- The key cannot be created. </exception> /// <exception cref="T:System.ArgumentOutOfRangeException"> /// <paramref name="dwKeySize" /> is out of range.</exception> 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); } } }