use of javax.crypto.spec.PBEKeySpec in project sling by apache.
the class TopologyRequestValidator method getCiperKey.
/**
* @param salt number of the key.
* @return the CupherKey.
* @throws UnsupportedEncodingException
* @throws NoSuchAlgorithmException
* @throws InvalidKeySpecException
*/
private Key getCiperKey(byte[] salt) throws UnsupportedEncodingException, NoSuchAlgorithmException, InvalidKeySpecException {
SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
// hashing the password 65K times takes 151ms, hashing 256 times takes 2ms.
// Since the salt has 2^^72 values, 256 times is probably good enough.
KeySpec spec = new PBEKeySpec(sharedKey.toCharArray(), salt, 256, 128);
SecretKey tmp = factory.generateSecret(spec);
SecretKey key = new SecretKeySpec(tmp.getEncoded(), "AES");
return key;
}
use of javax.crypto.spec.PBEKeySpec in project bnd by bndtools.
the class PasswordCryptor method encrypt.
public OutputStream encrypt(char[] password, OutputStream out) throws Exception {
PBEKeySpec pbeKeySpec = new PBEKeySpec(password);
SecretKey pbeKey = keyFac.generateSecret(pbeKeySpec);
final Cipher cipher = Cipher.getInstance("PBEWithMD5AndDES");
cipher.init(Cipher.ENCRYPT_MODE, pbeKey, pbeParamSpec);
return new CipherOutputStream(out, cipher);
}
use of javax.crypto.spec.PBEKeySpec in project ha-bridge by bwssytems.
the class BridgeSecurity method encrypt.
private String encrypt(String property) throws GeneralSecurityException, UnsupportedEncodingException {
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
SecretKey key = keyFactory.generateSecret(new PBEKeySpec(habridgeKey));
Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES");
pbeCipher.init(Cipher.ENCRYPT_MODE, key, new PBEParameterSpec(SALT, 20));
return base64Encode(pbeCipher.doFinal(property.getBytes("UTF-8")));
}
use of javax.crypto.spec.PBEKeySpec in project GeoGig by boundlessgeo.
the class Remote method encryptPassword.
public static String encryptPassword(String password) {
try {
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
SecretKey key = keyFactory.generateSecret(new PBEKeySpec(PASSWORD));
Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES");
pbeCipher.init(Cipher.ENCRYPT_MODE, key, new PBEParameterSpec(SALT, 20));
return Base64.encodeBytes(pbeCipher.doFinal(password.getBytes("UTF-8")));
} catch (Exception e) {
return password;
}
}
Aggregations