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); } } }
void Common(int dwKeySize, bool parameters) { // Microsoft RSA CSP can do between 384 and 16384 bits keypair LegalKeySizesValue = new KeySizes [1]; LegalKeySizesValue [0] = new KeySizes(384, 16384, 8); base.KeySize = dwKeySize; rsa = new RSAManaged(KeySize); rsa.KeyGenerated += new RSAManaged.KeyGeneratedEventHandler(OnKeyGenerated); persistKey = parameters; if (parameters) { return; } // no need to load - it cannot exists var p = new CspParameters(PROV_RSA_FULL); if (useMachineKeyStore) { p.Flags |= CspProviderFlags.UseMachineKeyStore; } store = new KeyPairPersistence(p); }
private void Common(int dwKeySize, CspParameters p) { // Microsoft RSA CSP can do between 384 and 16384 bits keypair LegalKeySizesValue = new KeySizes [1]; LegalKeySizesValue [0] = new KeySizes(384, 16384, 8); base.KeySize = dwKeySize; rsa = new RSAManaged(KeySize); rsa.KeyGenerated += new RSAManaged.KeyGeneratedEventHandler(OnKeyGenerated); persistKey = (p != null); if (p == null) { p = new CspParameters(PROV_RSA_FULL); #if NET_1_1 if (useMachineKeyStore) { p.Flags |= CspProviderFlags.UseMachineKeyStore; } #endif store = new KeyPairPersistence(p); // no need to load - it cannot exists } else { store = new KeyPairPersistence(p); store.Load(); if (store.KeyValue != null) { persisted = true; this.FromXmlString(store.KeyValue); } } }
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 }
private void Common(int dwKeySize, CspParameters p) { this.LegalKeySizesValue = new KeySizes[1]; this.LegalKeySizesValue[0] = new KeySizes(384, 16384, 8); base.KeySize = dwKeySize; this.rsa = new RSAManaged(this.KeySize); this.rsa.KeyGenerated += this.OnKeyGenerated; this.persistKey = (p != null); if (p == null) { p = new CspParameters(1); if (RSACryptoServiceProvider.useMachineKeyStore) { p.Flags |= CspProviderFlags.UseMachineKeyStore; } this.store = new KeyPairPersistence(p); } else { this.store = new KeyPairPersistence(p); this.store.Load(); if (this.store.KeyValue != null) { this.persisted = true; this.FromXmlString(this.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); } } }
void Common(CspParameters parameters) { store = new KeyPairPersistence(parameters); store.Load(); if (store.KeyValue != null) { persisted = true; this.FromXmlString(store.KeyValue); } }
void Common(CspParameters parameters) { store = new KeyPairPersistence(parameters); store.Load(); if (store.KeyValue != null) { persisted = true; this.FromXmlString(store.KeyValue); } privateKeyExportable = (parameters.Flags & CspProviderFlags.UseNonExportableKey) == 0; }
void Common(CspParameters p) { store = new KeyPairPersistence(p); bool exists = store.Load(); bool required = (p.Flags & CspProviderFlags.UseExistingKey) != 0; if (required && !exists) { throw new CryptographicException("Keyset does not exist"); } if (store.KeyValue != null) { persisted = true; FromXmlString(store.KeyValue); } }
private void Common(int dwKeySize, CspParameters p) { // Microsoft RSA CSP can do between 384 and 16384 bits keypair LegalKeySizesValue = new KeySizes [1]; LegalKeySizesValue [0] = new KeySizes(384, 16384, 8); base.KeySize = dwKeySize; rsa = new RSAManaged(KeySize); rsa.KeyGenerated += new RSAManaged.KeyGeneratedEventHandler(OnKeyGenerated); persistKey = (p != null); if (p == null) { p = new CspParameters(PROV_RSA_FULL); if (useMachineKeyStore) { p.Flags |= CspProviderFlags.UseMachineKeyStore; } store = new KeyPairPersistence(p); // no need to load - it cannot exists } else { store = new KeyPairPersistence(p); bool exists = store.Load(); bool required = (p.Flags & CspProviderFlags.UseExistingKey) != 0; if (required && !exists) { throw new CryptographicException("Keyset does not exist"); } if (store.KeyValue != null) { persisted = true; this.FromXmlString(store.KeyValue); } } }
public void ImportCspBlob(byte[] keyBlob) { if (keyBlob == null) { throw new ArgumentNullException("keyBlob"); } RSA rsa = CryptoConvert.FromCapiKeyBlob(keyBlob); if (rsa is RSACryptoServiceProvider) { // default (if no change are present in machine.config) RSAParameters rsap = rsa.ExportParameters(!(rsa as RSACryptoServiceProvider).PublicOnly); ImportParameters(rsap); } else { // we can't know from RSA if the private key is available try { // so we try it... RSAParameters rsap = rsa.ExportParameters(true); ImportParameters(rsap); } catch { // and fall back RSAParameters rsap = rsa.ExportParameters(false); ImportParameters(rsap); } } var p = new CspParameters(PROV_RSA_FULL); p.KeyNumber = keyBlob [5] == 0x24 ? AT_SIGNATURE : AT_KEYEXCHANGE; if (useMachineKeyStore) { p.Flags |= CspProviderFlags.UseMachineKeyStore; } store = new KeyPairPersistence(p); }