aboutsummaryrefslogtreecommitdiffstats
path: root/security-utils/src/main/java/com/yahoo/security/KeyStoreUtils.java
blob: 1e3f3cca386cb429108f8b9e426a6d359c7d2cec (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copyright Yahoo. 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]);
    }

}