Example usage for javax.crypto.spec PBEKeySpec getPassword

List of usage examples for javax.crypto.spec PBEKeySpec getPassword

Introduction

In this page you can find the example usage for javax.crypto.spec PBEKeySpec getPassword.

Prototype

public final char[] getPassword() 

Source Link

Document

Returns a copy of the password.

Usage

From source file:org.opennms.features.scv.impl.JCEKSSecureCredentialsVault.java

@Override
public Credentials getCredentials(String alias) {
    try {//from  w w  w.  j a v  a2 s. com
        KeyStore.PasswordProtection keyStorePP = new KeyStore.PasswordProtection(m_password);
        SecretKeyFactory factory = SecretKeyFactory.getInstance("PBE");

        KeyStore.SecretKeyEntry ske = (KeyStore.SecretKeyEntry) m_keystore.getEntry(alias, keyStorePP);
        if (ske == null) {
            return null;
        }

        PBEKeySpec keySpec = (PBEKeySpec) factory.getKeySpec(ske.getSecretKey(), PBEKeySpec.class);
        return fromBase64EncodedByteArray(new String(keySpec.getPassword()).getBytes());
    } catch (KeyStoreException | InvalidKeySpecException | NoSuchAlgorithmException | IOException
            | ClassNotFoundException | UnrecoverableEntryException e) {
        throw Throwables.propagate(e);
    }
}