use of javax.crypto.spec.PBEKeySpec in project GeoGig by boundlessgeo.
the class Remote method decryptPassword.
public static String decryptPassword(String password) {
try {
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
SecretKey key = keyFactory.generateSecret(new PBEKeySpec(PASSWORD));
Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES");
pbeCipher.init(Cipher.DECRYPT_MODE, key, new PBEParameterSpec(SALT, 20));
return new String(pbeCipher.doFinal(Base64.decode(password)));
} catch (Exception e) {
return password;
}
}
use of javax.crypto.spec.PBEKeySpec in project jdk8u_jdk by JetBrains.
the class MyPBKDF2SecretKey method getSecretKeyForPBKDF2.
/**
* Generate a PBKDF2 secret key using given algorithm.
*
* @param algoToDeriveKey PBKDF2 algorithm
* @return PBKDF2 secret key
* @throws NoSuchAlgorithmException
* @throws InvalidKeySpecException
*/
private SecretKey getSecretKeyForPBKDF2(String algoToDeriveKey) throws NoSuchAlgorithmException, InvalidKeySpecException {
SecretKeyFactory skf = SecretKeyFactory.getInstance(algoToDeriveKey);
PBEKeySpec spec = new PBEKeySpec(PASS_PHRASE.toCharArray(), this.salt, ITERATION_COUNT, KEY_SIZE);
return skf.generateSecret(spec);
}
use of javax.crypto.spec.PBEKeySpec in project symmetric-ds by JumpMind.
the class SecurityService method getDefaultSecretKey.
protected SecretKey getDefaultSecretKey() throws Exception {
String keyPassword = nextSecureHexString(8);
KeySpec keySpec = new PBEKeySpec(keyPassword.toCharArray(), SecurityConstants.SALT, SecurityConstants.ITERATION_COUNT, 56);
SecretKey secretKey = SecretKeyFactory.getInstance(SecurityConstants.ALGORITHM).generateSecret(keySpec);
return secretKey;
}
use of javax.crypto.spec.PBEKeySpec in project android_frameworks_base by DirtyUnicorns.
the class BackupManagerService method buildCharArrayKey.
private SecretKey buildCharArrayKey(String algorithm, char[] pwArray, byte[] salt, int rounds) {
try {
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(algorithm);
KeySpec ks = new PBEKeySpec(pwArray, salt, rounds, PBKDF2_KEY_SIZE);
return keyFactory.generateSecret(ks);
} catch (InvalidKeySpecException e) {
Slog.e(TAG, "Invalid key spec for PBKDF2!");
} catch (NoSuchAlgorithmException e) {
Slog.e(TAG, "PBKDF2 unavailable!");
}
return null;
}
use of javax.crypto.spec.PBEKeySpec in project tigervnc by TigerVNC.
the class PBKDF method getKey.
public byte[] getKey(byte[] _pass, byte[] salt, int iterations, int size) {
char[] pass = new char[_pass.length];
for (int i = 0; i < _pass.length; i++) {
pass[i] = (char) (_pass[i] & 0xff);
}
try {
PBEKeySpec spec = new PBEKeySpec(pass, salt, iterations, size * 8);
SecretKeyFactory skf = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
byte[] key = skf.generateSecret(spec).getEncoded();
return key;
} catch (InvalidKeySpecException e) {
} catch (NoSuchAlgorithmException e) {
}
return null;
}
Aggregations