public void generate()
            throws KeyStoreException, IOException, NoSuchAlgorithmException,
                   CertificateException, NoSuchProviderException,
                   InvalidKeyException, SignatureException
    {
        int keySize = 2048;
        char[] psw = this.keyInfo.getPassword().toCharArray();
        OutputStream fout = null;
                 
        try {
            fout = new java.io.FileOutputStream( this.file );
            
            // Create KeyStore
            this.keyStore = KeyStore.getInstance( "JKS" );
            this.keyStore.load( null, psw );
            
            // Create key
            CertAndKeyGen keypair = new CertAndKeyGen( "RSA", "SHA1WithRSA", null ); 
            X500Name x500Name = new X500Name(
                    this.keyInfo.getName(),
                    this.keyInfo.getOrgUnit(),
                    this.keyInfo.getCompany(),
                    this.keyInfo.getCity(),
                    this.keyInfo.getState(),
                    this.keyInfo.getCountryCode()
            );
            
            keypair.generate( keySize );
            PrivateKey privateKey = keypair.getPrivateKey();
            X509Certificate[] chain = new X509Certificate[ 1 ];
            chain[ 0 ] = keypair.getSelfCertificate(
                    x500Name,
                    new Date(),
                    35000 * 24L * 60L * 60L
            );
    
            // save key
            this.keyStore.setKeyEntry( this.keyInfo.getAlias(),
                    privateKey,
                    this.keyInfo.getPassword().toCharArray(),
                    chain
            );                    

            // store the keystore   
            this.keyStore.store( fout, psw );
        }
        finally {
            if ( fout != null ) {
                fout.close();
            }
        }
        
        return;
    }