Example usage for javax.security.auth.x500 X500PrivateCredential getAlias

List of usage examples for javax.security.auth.x500 X500PrivateCredential getAlias

Introduction

In this page you can find the example usage for javax.security.auth.x500 X500PrivateCredential getAlias.

Prototype


public String getAlias() 

Source Link

Document

Returns the KeyStore alias.

Usage

From source file:it.cnr.icar.eric.client.xml.registry.util.SecurityUtil.java

public String x500PrivateCredentialToAlias(X500PrivateCredential credential) {
    return credential.getAlias();
}

From source file:com.qut.middleware.crypto.impl.CryptoProcessorImpl.java

public KeyStore addKeyPair(KeyStore keyStore, String keyStorePassphrase, KeyPair keyPair, String keyPairName,
        String keyPairPassphrase, String keyPairSubjectDN) throws CryptoException {
    logger.debug("Adding key pair to existing key store");

    try {/*from  w  w  w.  j  a  va 2 s .c om*/
        // Create the public key certificate for storage in the key store.
        X509Certificate cert = generateV3Certificate(keyPair, keyPairSubjectDN);
        X500PrivateCredential privateCredentials = new X500PrivateCredential(cert, keyPair.getPrivate(),
                keyPairName);

        Certificate[] certChain = new X509Certificate[1];
        certChain[0] = privateCredentials.getCertificate();

        // Load our generated key store up. They all have the same password, which we set.
        keyStore.load(null, keyStorePassphrase.toCharArray());

        /* Add certificate which contains the public key and set the private key as a key entry in the key store */
        keyStore.setCertificateEntry(privateCredentials.getAlias(), privateCredentials.getCertificate());
        keyStore.setKeyEntry(privateCredentials.getAlias(), keyPair.getPrivate(),
                keyPairPassphrase.toCharArray(), certChain);

        return keyStore;
    } catch (NoSuchAlgorithmException e) {
        this.logger.error("NoSuchAlgorithmException thrown, " + e.getLocalizedMessage());
        this.logger.debug(e.toString());
        throw new CryptoException(e.getLocalizedMessage(), e);
    } catch (CertificateException e) {
        this.logger.error("CertificateException thrown, " + e.getLocalizedMessage());
        this.logger.debug(e.toString());
        throw new CryptoException(e.getLocalizedMessage(), e);
    } catch (KeyStoreException e) {
        this.logger.error("KeyStoreException thrown, " + e.getLocalizedMessage());
        this.logger.debug(e.toString());
        throw new CryptoException(e.getLocalizedMessage(), e);
    } catch (IOException e) {
        this.logger.error("IOException thrown, " + e.getLocalizedMessage());
        this.logger.debug(e.toString());
        throw new CryptoException(e.getLocalizedMessage(), e);
    }
}