Java Key Create getKeyStore(byte[] bytes, char[] password)

Here you can find the source of getKeyStore(byte[] bytes, char[] password)

Description

get Key Store

License

Open Source License

Declaration

public static KeyStore getKeyStore(byte[] bytes, char[] password) 

Method Source Code


//package com.java2s;
/*//from   w ww  .  j  ava2  s.  c  om
 *  Copyright (C) 2006 Tolven Inc 
 *
 * This library is free software; you can redistribute it and/or modify it under the terms of 
 * the GNU Lesser General Public License as published by the Free Software Foundation; either 
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
 * See the GNU Lesser General Public License for more details.
 * 
 * Contact: info@tolvenhealth.com
 */

import java.io.ByteArrayInputStream;

import java.security.KeyStore;

public class Main {
    public static final String TOLVEN_CREDENTIAL_FORMAT_PKCS12 = "pkcs12";

    public static KeyStore getKeyStore(byte[] bytes, char[] password) {
        ByteArrayInputStream bais = null;
        try {
            bais = new ByteArrayInputStream(bytes);
            try {
                KeyStore keyStore = KeyStore.getInstance(TOLVEN_CREDENTIAL_FORMAT_PKCS12);
                keyStore.load(bais, password);
                return keyStore;
            } catch (Exception ex) {
                throw new RuntimeException("Could not load keystore", ex);
            }
        } finally {
            if (bais != null)
                try {
                    bais.close();
                } catch (Exception ex) {
                    throw new RuntimeException("Could not close bytearrayinputstream after loading keystore", ex);
                }
        }
    }
}

Related

  1. getKeys()
  2. getKeySize(final Key key)
  3. getKeySize(PrivateKey key)
  4. getKeyStore()
  5. getKeyStore()
  6. getKeyStore(Certificate[] certificateChain, PrivateKey privateKey, char[] password)
  7. getKeyStore(char[] password)
  8. getKeyStore(File file, char[] storePass)
  9. getKeyStore(File keystore)