Search in sources :

Example 1 with RSAKeyPairGenerator

use of com.ingrian.security.nae.RSAKeyPairGenerator in project CipherTrust_Application_Protection by thalescpl-io.

the class KMIPGenKeys method main.

public static void main(String[] args) {
    if (args.length != 4) {
        usage();
    }
    int length = Integer.valueOf(args[3]);
    // add Ingrian provider to the list of JCE providers
    Security.addProvider(new IngrianProvider());
    // create KMIP Session - specify client X.509 certificate and keystore password
    KMIPSession session = KMIPSession.getSession(new NAEClientCertificate(args[0], args[1].toCharArray()));
    KeyPair sunPair = null;
    try {
        // verify Key Manager supports key pair generation
        if (!queryKeyGen(session)) {
            System.err.println("Key Manager does not support key pair generation");
            System.exit(0);
        }
        deleteIfNecessary(NAEKey.getPublicKey(args[2].trim() + Config.s_publicKeyGenSuffix, session));
        deleteIfNecessary(NAEKey.getPrivateKey(args[2].trim() + Config.s_privateKeyGenSuffix, session));
        RSAKeyPairGenerator keyGen = new RSAKeyPairGenerator();
        NAEParameterSpec spec = new NAEParameterSpec(args[2].trim(), length, (KMIPAttributes) null, session);
        keyGen.initialize(spec, null);
        sunPair = keyGen.generateKeyPair();
        PrivateKey priv = sunPair.getPrivate();
        PublicKey pub = sunPair.getPublic();
        NAEPrivateKey naePriv = (NAEPrivateKey) priv;
        NAEPublicKey naePub = (NAEPublicKey) pub;
        System.out.println("\n\n----------------------------\n");
        System.out.println("Key length = " + length);
        System.out.println("Private key name           : " + naePriv.getName());
        System.out.println("Private key format         : " + naePriv.getFormat());
        System.out.println("Private key algorithm      : " + naePriv.getAlgorithm());
        System.out.println("Private key encoded length : " + naePriv.getKeySize());
        System.out.println("Public key name            : " + naePub.getName());
        System.out.println("Public key format          : " + naePub.getFormat());
        System.out.println("Public key algorithm      : " + "" + naePub.getAlgorithm());
        System.out.println("Public key encoded length  : " + naePub.getKeySize());
    /* ((NAEPrivateKey)priv).delete();
            ((NAEPublicKey)pub).delete();*/
    } catch (Exception e) {
        System.out.println("The Cause is " + e.getMessage() + ".");
        e.printStackTrace();
    } finally {
        if (session != null)
            session.closeSession();
    }
}
Also used : KeyPair(java.security.KeyPair) NAEParameterSpec(com.ingrian.security.nae.NAEParameterSpec) PrivateKey(java.security.PrivateKey) NAEPrivateKey(com.ingrian.security.nae.NAEPrivateKey) NAEPrivateKey(com.ingrian.security.nae.NAEPrivateKey) PublicKey(java.security.PublicKey) NAEPublicKey(com.ingrian.security.nae.NAEPublicKey) RSAKeyPairGenerator(com.ingrian.security.nae.RSAKeyPairGenerator) NAEPublicKey(com.ingrian.security.nae.NAEPublicKey) NAEClientCertificate(com.ingrian.security.nae.NAEClientCertificate) NAEException(com.ingrian.security.nae.NAEException) IngrianProvider(com.ingrian.security.nae.IngrianProvider) KMIPSession(com.ingrian.security.nae.KMIPSession)

Aggregations

IngrianProvider (com.ingrian.security.nae.IngrianProvider)1 KMIPSession (com.ingrian.security.nae.KMIPSession)1 NAEClientCertificate (com.ingrian.security.nae.NAEClientCertificate)1 NAEException (com.ingrian.security.nae.NAEException)1 NAEParameterSpec (com.ingrian.security.nae.NAEParameterSpec)1 NAEPrivateKey (com.ingrian.security.nae.NAEPrivateKey)1 NAEPublicKey (com.ingrian.security.nae.NAEPublicKey)1 RSAKeyPairGenerator (com.ingrian.security.nae.RSAKeyPairGenerator)1 KeyPair (java.security.KeyPair)1 PrivateKey (java.security.PrivateKey)1 PublicKey (java.security.PublicKey)1