Exemplo n.º 1
0
        private void CreateKeystore(
            String myAlias,
            String peerAlias,
            AsymmetricCipherKeyPair myKey,
            X509Certificate myCert,
            X509Certificate peerCert,
            String filename,
            String password)
        {
            PKCS12Store pkcs12 = new PKCS12Store();

            pkcs12.setKeyEntry(
                myAlias,
                new AsymmetricKeyEntry(myKey.getPrivate()),
                new X509CertificateEntry[] { new X509CertificateEntry(myCert) });
            pkcs12.setCertificateEntry(peerAlias, new X509CertificateEntry(peerCert));

            System.IO.FileStream stream =
                new System.IO.FileStream(
                    keystoreFolder +
                    "\\" + filename + ".p12",
                    System.IO.FileMode.Create);
            pkcs12.save(stream, password.ToCharArray(), new SecureRandom());
            stream.Close();
        }
Exemplo n.º 2
0
        private static X509Certificate createCertificate(
            AsymmetricCipherKeyPair pair,
            string country,
            string organization,
            string locality,
            string state,
            string emailAddress,
            string commonName,
            BigInteger serialNumber,
            AsymmetricCipherKeyPair signer)
        {
            Hashtable attrs = new Hashtable();

            attrs.Add(X509Name.C, country);                     // Country
            attrs.Add(X509Name.O, organization);                // Organization
            attrs.Add(X509Name.L, locality);                    // Locality
            attrs.Add(X509Name.ST, state);                      // State/Province
            attrs.Add(X509Name.EmailAddress, emailAddress);
            attrs.Add(X509Name.CN, commonName);                 // Common Name

            // Create a certificate
            X509V3CertificateGenerator certGen = new X509V3CertificateGenerator();

            certGen.setSerialNumber(serialNumber);
            certGen.setIssuerDN(new X509Name(attrs));
            certGen.setNotBefore(DateTime.Today.Subtract(new TimeSpan(1, 0, 0, 0)));
            certGen.setNotAfter(DateTime.Today.AddDays(365));
            certGen.setSubjectDN(new X509Name(attrs));
            certGen.setPublicKey(pair.getPublic());
            certGen.setSignatureAlgorithm("SHA1WithRSAEncryption");

            return(certGen.generateX509Certificate(signer.getPrivate()));
        }
 public ScrambledKeyPair(AsymmetricCipherKeyPair pPair)
 {
     _pair = pPair;
     _publicKey = pPair.getPublic();
     _scrambledModulus = scrambleModulus((_publicKey as RSAKeyParameters).getModulus());
     _privateKey = pPair.getPrivate();
 }
Exemplo n.º 4
0
        public ScrambledKeyPair(AsymmetricCipherKeyPair pPair)
        {
            _pair = pPair;
            AsymmetricKeyParameter publicKey        = pPair.getPublic();
            RSAKeyParameters       rsaKeyParameters = publicKey as RSAKeyParameters;

            if (rsaKeyParameters != null)
            {
                ScrambledModulus = ScrambleModulus(rsaKeyParameters.getModulus());
            }
            PrivateKey = pPair.getPrivate();
        }
Exemplo n.º 5
0
        private RSAKeyParameters generateKeys()
        {
            RSAKeyPairGenerator        kpg   = new RSAKeyPairGenerator();
            RSAKeyGenerationParameters parms = new RSAKeyGenerationParameters(
                BigInteger.valueOf(0x11), new SecureRandom(), keySize,
                certainty);

            kpg.init(parms);
            AsymmetricCipherKeyPair pair = kpg.generateKeyPair();

            privateKey = (RSAKeyParameters)pair.getPrivate();
            return((RSAKeyParameters)pair.getPublic());
        }