use of javax.crypto.SecretKey in project opennms by OpenNMS.
the class JCEKSSecureCredentialsVault method setCredentials.
@Override
public void setCredentials(String alias, Credentials credentials) {
try {
byte[] credentialBytes = toBase64EncodedByteArray(credentials);
SecretKeyFactory factory = SecretKeyFactory.getInstance("PBE");
SecretKey generatedSecret = factory.generateSecret(new PBEKeySpec(new String(credentialBytes).toCharArray(), m_salt, m_iterationCount, m_keyLength));
KeyStore.PasswordProtection keyStorePP = new KeyStore.PasswordProtection(m_password);
m_keystore.setEntry(alias, new KeyStore.SecretKeyEntry(generatedSecret), keyStorePP);
writeKeystoreToDisk();
} catch (KeyStoreException | InvalidKeySpecException | NoSuchAlgorithmException | IOException e) {
throw Throwables.propagate(e);
}
}
use of javax.crypto.SecretKey in project opennms by OpenNMS.
the class JCEKSSecureCredentialsVault method setCredentials.
@Override
public void setCredentials(String alias, Credentials credentials) {
try {
byte[] credentialBytes = toBase64EncodedByteArray(credentials);
SecretKeyFactory factory = SecretKeyFactory.getInstance("PBE");
SecretKey generatedSecret = factory.generateSecret(new PBEKeySpec(new String(credentialBytes).toCharArray(), m_salt, m_iterationCount, m_keyLength));
KeyStore.PasswordProtection keyStorePP = new KeyStore.PasswordProtection(m_password);
m_keystore.setEntry(alias, new KeyStore.SecretKeyEntry(generatedSecret), keyStorePP);
writeKeystoreToDisk();
} catch (KeyStoreException | InvalidKeySpecException | NoSuchAlgorithmException | IOException e) {
throw Throwables.propagate(e);
}
}
use of javax.crypto.SecretKey in project newsrob by marianokamp.
the class EntryManager method getSecretKey.
private static SecretKey getSecretKey() throws InvalidKeyException, UnsupportedEncodingException, NoSuchAlgorithmException, InvalidKeySpecException {
DESKeySpec keySpec = new DESKeySpec("EntryManager.class".getBytes("UTF8"));
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
SecretKey secretKey = keyFactory.generateSecret(keySpec);
return secretKey;
}
use of javax.crypto.SecretKey in project UltimateAndroid by cymcsg.
the class DefaultAppLock method encryptPassword.
private String encryptPassword(String clearText) {
try {
DESKeySpec keySpec = new DESKeySpec(PASSWORD_ENC_SECRET.getBytes("UTF-8"));
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
SecretKey key = keyFactory.generateSecret(keySpec);
Cipher cipher = Cipher.getInstance("DES");
cipher.init(Cipher.ENCRYPT_MODE, key);
String encrypedPwd = Base64.encodeToString(cipher.doFinal(clearText.getBytes("UTF-8")), Base64.DEFAULT);
return encrypedPwd;
} catch (Exception e) {
}
return clearText;
}
use of javax.crypto.SecretKey in project UltimateAndroid by cymcsg.
the class DefaultAppLock method decryptPassword.
private String decryptPassword(String encryptedPwd) {
try {
DESKeySpec keySpec = new DESKeySpec(PASSWORD_ENC_SECRET.getBytes("UTF-8"));
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
SecretKey key = keyFactory.generateSecret(keySpec);
byte[] encryptedWithoutB64 = Base64.decode(encryptedPwd, Base64.DEFAULT);
Cipher cipher = Cipher.getInstance("DES");
cipher.init(Cipher.DECRYPT_MODE, key);
byte[] plainTextPwdBytes = cipher.doFinal(encryptedWithoutB64);
return new String(plainTextPwdBytes);
} catch (Exception e) {
}
return encryptedPwd;
}
Aggregations