예제 #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
        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)
 {
     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);
         }
     }
 }
예제 #4
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);
                }
            }
        }