use of javax.crypto.spec.PBEKeySpec in project jdk8u_jdk by JetBrains.
the class PBKDF2TranslateTest method getSecretKeyForPBKDF2.
/**
* Generate a PBKDF2 secret key using given algorithm.
*/
private SecretKey getSecretKeyForPBKDF2(String algoDeriveKey, byte[] salt) throws NoSuchAlgorithmException, InvalidKeySpecException {
SecretKeyFactory skf = SecretKeyFactory.getInstance(algoDeriveKey);
PBEKeySpec spec = new PBEKeySpec(PASS_PHRASE.toCharArray(), salt, ITERATION_COUNT, KEY_SIZE);
return skf.generateSecret(spec);
}
use of javax.crypto.spec.PBEKeySpec in project android_frameworks_base by AOSPA.
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 wildfly by wildfly.
the class VaultSession method computeMaskedPassword.
/**
* Method to compute masked password based on class attributes.
*
* @return masked password prefixed with {link @PicketBoxSecurityVault.PASS_MASK_PREFIX}.
* @throws Exception
*/
private String computeMaskedPassword() throws Exception {
// Create the PBE secret key
SecretKeyFactory factory = SecretKeyFactory.getInstance(VAULT_ENC_ALGORITHM);
char[] password = "somearbitrarycrazystringthatdoesnotmatter".toCharArray();
PBEParameterSpec cipherSpec = new PBEParameterSpec(salt.getBytes(), iterationCount);
PBEKeySpec keySpec = new PBEKeySpec(password);
SecretKey cipherKey = factory.generateSecret(keySpec);
String maskedPass = PBEUtils.encode64(keystorePassword.getBytes(), VAULT_ENC_ALGORITHM, cipherKey, cipherSpec);
return PicketBoxSecurityVault.PASS_MASK_PREFIX + maskedPass;
}
use of javax.crypto.spec.PBEKeySpec in project robovm by robovm.
the class SecretKeyFactoryTest method test_PBKDF2_UTF8.
private void test_PBKDF2_UTF8(char[] password, byte[] salt, int iterations, int keyLength, byte[] expected) throws Exception {
SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
KeySpec ks = new PBEKeySpec(password, salt, iterations, keyLength);
SecretKey key = factory.generateSecret(ks);
assertTrue(Arrays.equals(expected, key.getEncoded()));
}
use of javax.crypto.spec.PBEKeySpec in project robovm by robovm.
the class SecretKeyFactoryTest method test_PBKDF2_required_parameters.
public void test_PBKDF2_required_parameters() throws Exception {
SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
// PBEKeySpecs password only constructor
try {
KeySpec ks = new PBEKeySpec(null);
factory.generateSecret(ks);
fail();
} catch (InvalidKeySpecException expected) {
}
try {
KeySpec ks = new PBEKeySpec(new char[0]);
factory.generateSecret(ks);
fail();
} catch (InvalidKeySpecException expected) {
}
try {
KeySpec ks = new PBEKeySpec(PASSWORD);
factory.generateSecret(ks);
fail();
} catch (InvalidKeySpecException expected) {
}
// PBEKeySpecs constructor without key length
try {
KeySpec ks = new PBEKeySpec(null, SALT, ITERATIONS);
factory.generateSecret(ks);
fail();
} catch (InvalidKeySpecException expected) {
}
try {
KeySpec ks = new PBEKeySpec(new char[0], SALT, ITERATIONS);
factory.generateSecret(ks);
fail();
} catch (InvalidKeySpecException expected) {
}
try {
KeySpec ks = new PBEKeySpec(PASSWORD, SALT, ITERATIONS);
factory.generateSecret(ks);
fail();
} catch (InvalidKeySpecException expected) {
}
try {
KeySpec ks = new PBEKeySpec(null, SALT, ITERATIONS, KEY_LENGTH);
factory.generateSecret(ks);
fail();
} catch (IllegalArgumentException expected) {
}
try {
KeySpec ks = new PBEKeySpec(new char[0], SALT, ITERATIONS, KEY_LENGTH);
factory.generateSecret(ks);
fail();
} catch (IllegalArgumentException expected) {
}
KeySpec ks = new PBEKeySpec(PASSWORD, SALT, ITERATIONS, KEY_LENGTH);
factory.generateSecret(ks);
}
Aggregations