Пример #1
0
        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);
                }
            }
        }
Пример #2
0
        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);
                }
            }
        }
Пример #3
0
 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;
 }
Пример #5
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);
            }
        }
Пример #6
0
        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);
                }
            }
        }