Example usage for java.security KeyStore setKeyEntry

List of usage examples for java.security KeyStore setKeyEntry

Introduction

In this page you can find the example usage for java.security KeyStore setKeyEntry.

Prototype

public final void setKeyEntry(String alias, byte[] key, Certificate[] chain) throws KeyStoreException 

Source Link

Document

Assigns the given key (that has already been protected) to the given alias.

Usage

From source file:com.aqnote.shared.cryptology.cert.util.KeyStoreUtil.java

public static KeyStore createPCSK12KeyStore(String alias, Key key, char[] pwd, Certificate[] chain)
        throws CertException {

    try {//  w  w w  .  j  a v  a 2  s.c om
        KeyStore keyStore = KeyStore.getInstance(PKCS12_STORE_TYPE);
        keyStore.load(null, pwd);
        if (pwd == null) {
            keyStore.setKeyEntry(alias, key.getEncoded(), chain);
        } else {
            keyStore.setKeyEntry(alias, key, pwd, chain);
        }
        return keyStore;
    } catch (KeyStoreException e) {
        throw new CertException(e);
    } catch (NoSuchAlgorithmException e) {
        throw new CertException(e);
    } catch (CertificateException e) {
        throw new CertException(e);
    } catch (IOException e) {
        throw new CertException(e);
    }
}