diff options
author | gjoranv <gjoranv@gmail.com> | 2018-10-19 10:47:54 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-19 10:47:54 +0200 |
commit | 5ac10d9e9c036d0448ebd4e1ff9d3704a675b69e (patch) | |
tree | eaf25ba520a44df4ddf7244024f9e5072f676a4b /security-utils/src/main/java/com/yahoo/security/KeyStoreUtils.java | |
parent | 182384b808434b3f449f459f9bce113f0aa5cc16 (diff) | |
parent | 1c3999a1faa10d2def03f43ba7ce22bb83997e26 (diff) |
Merge pull request #7344 from vespa-engine/bjorncs/security-lib
Move classes in com.yahoo.security to security-utils
Diffstat (limited to 'security-utils/src/main/java/com/yahoo/security/KeyStoreUtils.java')
-rw-r--r-- | security-utils/src/main/java/com/yahoo/security/KeyStoreUtils.java | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/security-utils/src/main/java/com/yahoo/security/KeyStoreUtils.java b/security-utils/src/main/java/com/yahoo/security/KeyStoreUtils.java new file mode 100644 index 00000000000..f0c4d99bf69 --- /dev/null +++ b/security-utils/src/main/java/com/yahoo/security/KeyStoreUtils.java @@ -0,0 +1,34 @@ +// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.security; + +import java.io.BufferedOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.io.UncheckedIOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.security.GeneralSecurityException; +import java.security.KeyStore; + +/** + * @author bjorncs + */ +public class KeyStoreUtils { + private KeyStoreUtils() {} + + public static void writeKeyStoreToFile(KeyStore keyStore, Path file, char[] password) { + try (OutputStream out = new BufferedOutputStream(Files.newOutputStream(file))) { + keyStore.store(out, password); + } catch (IOException e) { + throw new UncheckedIOException(e); + } catch (GeneralSecurityException e) { + throw new RuntimeException(e); + } + + } + + public static void writeKeyStoreToFile(KeyStore keyStore, Path file) { + writeKeyStoreToFile(keyStore, file, new char[0]); + } + +} |