use of javax.crypto.spec.PBEParameterSpec in project android-delicious by lexs.
the class ObscuredSharedPreferences method encrypt.
protected String encrypt(String value) {
try {
final byte[] bytes = value != null ? value.getBytes(UTF8) : new byte[0];
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
SecretKey key = keyFactory.generateSecret(new PBEKeySpec(secret));
Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES");
pbeCipher.init(Cipher.ENCRYPT_MODE, key, new PBEParameterSpec(getSalt(), 20));
return new String(Base64.encode(pbeCipher.doFinal(bytes), Base64.NO_WRAP), UTF8);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of javax.crypto.spec.PBEParameterSpec in project android-delicious by lexs.
the class ObscuredSharedPreferences method decrypt.
protected String decrypt(String value) {
try {
final byte[] bytes = value != null ? Base64.decode(value, Base64.DEFAULT) : new byte[0];
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
SecretKey key = keyFactory.generateSecret(new PBEKeySpec(secret));
Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES");
pbeCipher.init(Cipher.DECRYPT_MODE, key, new PBEParameterSpec(getSalt(), 20));
return new String(pbeCipher.doFinal(bytes), UTF8);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of javax.crypto.spec.PBEParameterSpec in project platformlayer by platformlayer.
the class NexusLdapPasswords method buildCipher.
private Cipher buildCipher(String passphrase, byte[] salt, int mode) throws InvalidKeySpecException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException {
KeySpec keySpec = new PBEKeySpec(passphrase.toCharArray());
SecretKey key = SecretKeyFactory.getInstance(KEY_ALGORITHM, bouncyCastleProvider).generateSecret(keySpec);
Cipher cipher = Cipher.getInstance(KEY_ALGORITHM, bouncyCastleProvider);
PBEParameterSpec paramSpec = new PBEParameterSpec(salt, iterationCount);
cipher.init(mode, key, paramSpec);
return cipher;
}
use of javax.crypto.spec.PBEParameterSpec in project ButterRemote-Android by se-bastiaan.
the class ObscuredSharedPreferences method decrypt.
protected String decrypt(String value) {
try {
final byte[] bytes = value != null ? Base64.decode(value, Base64.DEFAULT) : new byte[0];
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(PBE_WITH_MD5_AND_DES);
SecretKey key = keyFactory.generateSecret(new PBEKeySpec(SEKRIT));
Cipher pbeCipher = Cipher.getInstance(PBE_WITH_MD5_AND_DES);
pbeCipher.init(Cipher.DECRYPT_MODE, key, new PBEParameterSpec(Settings.Secure.getString(context.getContentResolver(), Settings.System.ANDROID_ID).getBytes(UTF8), 20));
return new String(pbeCipher.doFinal(bytes), UTF8);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of javax.crypto.spec.PBEParameterSpec in project symmetric-ds by JumpMind.
the class SecurityService method initializeCipher.
protected void initializeCipher(Cipher cipher, int mode) throws Exception {
AlgorithmParameterSpec paramSpec = Cipher.getMaxAllowedParameterSpec(cipher.getAlgorithm());
if (paramSpec instanceof PBEParameterSpec || (paramSpec == null && cipher.getAlgorithm().startsWith("PBE"))) {
paramSpec = new PBEParameterSpec(SecurityConstants.SALT, SecurityConstants.ITERATION_COUNT);
cipher.init(mode, secretKey, paramSpec);
} else if (paramSpec instanceof IvParameterSpec) {
paramSpec = new IvParameterSpec(SecurityConstants.SALT);
cipher.init(mode, secretKey, paramSpec);
} else {
cipher.init(mode, secretKey, (AlgorithmParameterSpec) null);
}
}
Aggregations