List of usage examples for java.security KeyStore store
public final void store(OutputStream stream, char[] password) throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException
From source file:com.aqnote.shared.cryptology.cert.util.KeyStoreUtil.java
public static String coverKeyStore2String(KeyStore keyStore, char[] passwd) throws CertException { try {//from ww w.ja va 2 s . c o m CircularByteBuffer cbb = new CircularByteBuffer(CircularByteBuffer.INFINITE_SIZE); keyStore.store(cbb.getOutputStream(), passwd); return Base64.encodeBase64String(StreamUtil.stream2Bytes(cbb.getInputStream())); } 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); } }
From source file:energy.usef.environment.tool.security.KeystoreService.java
public static void createNewStoreIfNeeded(String fileName, char[] keystorePassword) throws KeyStoreException, NoSuchAlgorithmException, CertificateException { File file = new File(fileName); if (file != null && file.exists()) { return;//from ww w.j ava 2 s . co m } KeyStore ks = KeyStore.getInstance(JCEKS); try (OutputStream os = new FileOutputStream(fileName)) { ks.load(null, keystorePassword); ks.store(os, keystorePassword); } catch (IOException e) { LOGGER.error("Error while creating the Keystore: {}. Keystore will not be created." + e.getMessage() + "\n" + e); throw new RuntimeException(e); } }
From source file:org.computerist.ssltools.zap.ZapSslCertificateUtils.java
/** * @param keystore//from w w w. j a va 2 s.com * @return * @throws KeyStoreException * @throws IOException * @throws CertificateException * @throws NoSuchAlgorithmException */ public static final String keyStore2String(KeyStore keystore) throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); keystore.store(baos, FixedSslCertificateService.PASSPHRASE); final byte[] bytes = baos.toByteArray(); baos.close(); return Base64.encodeBase64URLSafeString(bytes); }
From source file:Main.java
public static void addCertToKnownServersStore(Certificate cert, Context context) throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException { KeyStore knownServers = getKnownServersStore(context); knownServers.setCertificateEntry(Integer.toString(cert.hashCode()), cert); FileOutputStream fos = null;/*from www .j av a2 s. co m*/ try { fos = context.openFileOutput(LOCAL_TRUSTSTORE_FILENAME, Context.MODE_PRIVATE); knownServers.store(fos, LOCAL_TRUSTSTORE_PASSWORD.toCharArray()); } finally { fos.close(); } }
From source file:org.openanzo.rdf.utils.KeystoreUtils.java
/** * /*from w w w .jav a2 s. c om*/ * @param filename * @param password * @param store * @throws IOException * @throws GeneralSecurityException */ public static final void writeStoreToFile(String filename, String password, KeyStore store) throws IOException, GeneralSecurityException { OutputStream outputStream = null; try { outputStream = org.apache.commons.io.FileUtils.openOutputStream(new File(filename)); store.store(outputStream, password.toCharArray()); } finally { if (outputStream != null) { outputStream.close(); } } }
From source file:org.jboss.as.test.integration.auditlog.AuditLogToTLSSyslogSetup.java
private static void createTemporaryKeyStoreFile(KeyStore keyStore, File outputFile) throws Exception { try (FileOutputStream fos = new FileOutputStream(outputFile)) { keyStore.store(fos, KEYSTORE_CREATION_PASSWORD); }/*from ww w. ja v a 2s. co m*/ }
From source file:org.apache.abdera2.common.security.KeyHelper.java
public static void saveKeystore(KeyStore ks, String file, String password) throws KeyStoreException, NoSuchAlgorithmException, CertificateException, FileNotFoundException, IOException { FileOutputStream out = new FileOutputStream(file); ks.store(out, password.toCharArray()); out.close();/*from w w w . ja v a2 s . c o m*/ }
From source file:org.apache.hive.service.server.TestHS2HttpServerPamConfiguration.java
private static void createDefaultKeyStore() throws KeyStoreException, CertificateException, NoSuchAlgorithmException, IOException { KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType()); char[] password = keyStorePassword.toCharArray(); ks.load(null, null);/*from w w w . j a va2 s.co m*/ // Store away the keystore. try (FileOutputStream fos = new FileOutputStream(sslKeyStorePath)) { ks.store(fos, password); } }
From source file:org.metaeffekt.dcc.commons.pki.KeyUtils.java
public static void persistKeyStore(KeyStore keyStoreObject, File file, char[] password) throws GeneralSecurityException, IOException { OutputStream out = null;/* w ww. j a v a2s . co m*/ try { file.getParentFile().mkdirs(); out = new BufferedOutputStream(new FileOutputStream(file)); keyStoreObject.store(out, password); } finally { IOUtils.closeQuietly(out); } }
From source file:org.zaproxy.zap.extension.dynssl.SslCertificateUtils.java
/** * @param keystore//from www . j a v a 2 s. co m * @return * @throws KeyStoreException * @throws IOException * @throws CertificateException * @throws NoSuchAlgorithmException */ public static final String keyStore2String(KeyStore keystore) throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); keystore.store(baos, SslCertificateService.PASSPHRASE); final byte[] bytes = baos.toByteArray(); baos.close(); return Base64.encodeBase64URLSafeString(bytes); }