Search in sources :

Example 96 with PBEKeySpec

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;
}
Also used : PBEKeySpec(javax.crypto.spec.PBEKeySpec) SecretKey(javax.crypto.SecretKey) SecretKeySpec(javax.crypto.spec.SecretKeySpec) SecretKeySpec(javax.crypto.spec.SecretKeySpec) KeySpec(java.security.spec.KeySpec) PBEKeySpec(javax.crypto.spec.PBEKeySpec) SecretKeyFactory(javax.crypto.SecretKeyFactory)

Example 97 with PBEKeySpec

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);
}
Also used : PBEKeySpec(javax.crypto.spec.PBEKeySpec) SecretKey(javax.crypto.SecretKey) CipherOutputStream(javax.crypto.CipherOutputStream) Cipher(javax.crypto.Cipher)

Example 98 with PBEKeySpec

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")));
}
Also used : PBEKeySpec(javax.crypto.spec.PBEKeySpec) SecretKey(javax.crypto.SecretKey) Cipher(javax.crypto.Cipher) SecretKeyFactory(javax.crypto.SecretKeyFactory) PBEParameterSpec(javax.crypto.spec.PBEParameterSpec)

Example 99 with PBEKeySpec

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;
    }
}
Also used : PBEKeySpec(javax.crypto.spec.PBEKeySpec) SecretKey(javax.crypto.SecretKey) Cipher(javax.crypto.Cipher) SecretKeyFactory(javax.crypto.SecretKeyFactory) PBEParameterSpec(javax.crypto.spec.PBEParameterSpec) MalformedURLException(java.net.MalformedURLException)

Aggregations

PBEKeySpec (javax.crypto.spec.PBEKeySpec)99 SecretKeyFactory (javax.crypto.SecretKeyFactory)75 SecretKey (javax.crypto.SecretKey)55 Cipher (javax.crypto.Cipher)36 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)35 PBEParameterSpec (javax.crypto.spec.PBEParameterSpec)31 KeySpec (java.security.spec.KeySpec)24 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)23 KeyStoreException (java.security.KeyStoreException)16 IOException (java.io.IOException)15 SecretKeySpec (javax.crypto.spec.SecretKeySpec)14 CertificateException (java.security.cert.CertificateException)12 UnrecoverableKeyException (java.security.UnrecoverableKeyException)11 KeyStore (java.security.KeyStore)10 CertificateEncodingException (java.security.cert.CertificateEncodingException)8 PKCS8EncodedKeySpec (java.security.spec.PKCS8EncodedKeySpec)7 EncryptedPrivateKeyInfo (javax.crypto.EncryptedPrivateKeyInfo)7 UnsupportedEncodingException (java.io.UnsupportedEncodingException)6 InvalidKeyException (java.security.InvalidKeyException)6 Key (java.security.Key)6