acciduck / jscep

Automatically exported from code.google.com/p/jscep
MIT License
0 stars 0 forks source link

Provide a java.security.KeyStore example #12

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Add an example to show interaction with KeyStores.

Original issue reported on code.google.com by davidgrant41 on 26 Feb 2010 at 2:33

GoogleCodeExporter commented 8 years ago
Here is the code that I use. I hope it helps.

//Generate the public and private keys
        Security.addProvider(new BouncyCastleProvider());   //Register BouncyCastle as our Security Provider. This is needed to generate the identity later
        SecureRandom rand = new SecureRandom(); //This is a better random number generator than Math.random and is required.
        JDKKeyPairGenerator.RSA keyPairGen = new JDKKeyPairGenerator.RSA(); //This is the object that will generate the public and private keys       
        keyPairGen.initialize(2048, rand);  //We tell it how many bits to use, 2048 is good enough.
        KeyPair keyPair = keyPairGen.generateKeyPair(); //Finally we call generate

        //Generate the identiy that we are going to pass to the SCEP server
        X509Certificate identity = null;

        try {            
            X500Principal principal = new X500Principal("CN=" + username);
            identity = X509Util.createEphemeralCertificate(principal, keyPair); //Generate with the key pair created above
        } catch (GeneralSecurityException ex) {
            log.log(Level.SEVERE, null, ex);
            System.exit(CANT_GENERATE_IDENTITY_ERROR);
        }

Original comment by hir...@gmail.com on 9 Nov 2010 at 7:16

GoogleCodeExporter commented 8 years ago
Thanks Hiro!

Original comment by *dgr...@ubq.thrupoint.net on 9 Nov 2010 at 11:21

GoogleCodeExporter commented 8 years ago

Original comment by da...@grant.org.uk on 13 Jul 2011 at 6:37

GoogleCodeExporter commented 8 years ago
This issue was closed by revision r1441.

Original comment by da...@grant.org.uk on 11 Aug 2012 at 8:36

GoogleCodeExporter commented 8 years ago

Original comment by da...@grant.org.uk on 21 Aug 2012 at 11:55