List of usage examples for javax.crypto SecretKeyFactory getKeySpec
public final KeySpec getKeySpec(SecretKey key, Class<?> keySpec) throws InvalidKeySpecException
From source file:org.kuali.rice.core.impl.encryption.EncryptionServiceImplTest.java
private String generateDESedeKey() throws Exception { KeyGenerator keygen = KeyGenerator.getInstance("DESede"); SecretKey desedeKey = keygen.generateKey(); SecretKeyFactory desedeFactory = SecretKeyFactory.getInstance("DESede"); DESedeKeySpec desedeSpec = (DESedeKeySpec) desedeFactory.getKeySpec(desedeKey, javax.crypto.spec.DESedeKeySpec.class); byte[] rawDesedeKey = desedeSpec.getKey(); return new String(Base64.encodeBase64(rawDesedeKey)); }
From source file:org.opennms.features.scv.impl.JCEKSSecureCredentialsVault.java
@Override public Credentials getCredentials(String alias) { try {// w ww. j a v a2 s. c o m 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); } }