final OpenSSLPBEParametersGenerator generator = new OpenSSLPBEParametersGenerator(); generator.init(password, salt); final ParametersWithIV ivParam = (ParametersWithIV)generator.generateDerivedParameters(16, 8); final KeyParameter keyParameter = (KeyParameter)ivParam.getParameters();
/** * Generate a key parameter derived from the password, salt, and iteration * count we are currently initialised with. * * @param keySize the size of the key we want (in bits) * @return a KeyParameter object. * @exception IllegalArgumentException if the key length larger than the base hash size. */ public CipherParameters generateDerivedParameters( int keySize) { keySize = keySize / 8; byte[] dKey = generateDerivedKey(keySize); return new KeyParameter(dKey, 0, keySize); }
/** * Get password and generate key and iv. * * @param password * The password to use in key generation * @param salt * The salt to use in key generation * @return The CipherParameters containing the created key */ private static CipherParameters getAESPasswordKey(final char[] password, final byte[] salt) { final PBEParametersGenerator generator = new OpenSSLPBEParametersGenerator(); generator.init(PBEParametersGenerator.PKCS5PasswordToBytes(password), salt, NUMBER_OF_ITERATIONS); final ParametersWithIV key = (ParametersWithIV) generator.generateDerivedParameters(KEY_LENGTH, IV_LENGTH); return key; }
/** * Generate a key parameter for use with a MAC derived from the password, * salt, and iteration count we are currently initialised with. * * @param keySize the size of the key we want (in bits) * @return a KeyParameter object. * @exception IllegalArgumentException if the key length larger than the base hash size. */ public CipherParameters generateDerivedMacParameters( int keySize) { return generateDerivedParameters(keySize); } }
/** * Get password and generate key and iv. * * @param password * The password to use in key generation * @param salt * The salt to use in key generation * @return The CipherParameters containing the created key */ private static CipherParameters getAESPasswordKey(final char[] password, final byte[] salt) { final PBEParametersGenerator generator = new OpenSSLPBEParametersGenerator(); generator.init(PBEParametersGenerator.PKCS5PasswordToBytes(password), salt, NUMBER_OF_ITERATIONS); final ParametersWithIV key = (ParametersWithIV) generator.generateDerivedParameters(KEY_LENGTH, IV_LENGTH); return key; }
/** * Generate a key parameter for use with a MAC derived from the password, * salt, and iteration count we are currently initialised with. * * @param keySize the size of the key we want (in bits) * @return a KeyParameter object. * @exception IllegalArgumentException if the key length larger than the base hash size. */ public CipherParameters generateDerivedMacParameters( int keySize) { return generateDerivedParameters(keySize); } }
OpenSSLPBEParametersGenerator pGen = new OpenSSLPBEParametersGenerator(); pGen.init(Strings.toByteArray(pbeSpec.getPassword()), pbeSpec.getSalt()); return new SecretKeySpec(((KeyParameter)pGen.generateDerivedParameters(pbeSpec.getKeyLength())).getKey(), "OpenSSLPBKDF");
private static KeyParameter getKey( char[] password, int keyLength, byte[] salt, boolean des2) throws PEMException { PBEParametersGenerator paramsGen = new OpenSSLPBEParametersGenerator(); paramsGen.init(PBEParametersGenerator.PKCS5PasswordToBytes(password), salt, 1); KeyParameter kp = (KeyParameter)paramsGen.generateDerivedParameters(keyLength * 8); if (des2 && kp.getKey().length == 24) { // For DES2, we must copy first 8 bytes into the last 8 bytes. byte[] key = kp.getKey(); System.arraycopy(key, 0, key, 16, 8); return new KeyParameter(key); } return kp; } }
/** * Generate a key parameter derived from the password, salt, and iteration * count we are currently initialised with. * * @param keySize the size of the key we want (in bits) * @return a KeyParameter object. * @exception IllegalArgumentException if the key length larger than the base hash size. */ public CipherParameters generateDerivedParameters( int keySize) { keySize = keySize / 8; byte[] dKey = generateDerivedKey(keySize); return new KeyParameter(dKey, 0, keySize); }
private static KeyParameter getKey( char[] password, int keyLength, byte[] salt, boolean des2) throws PEMException { PBEParametersGenerator paramsGen = new OpenSSLPBEParametersGenerator(); paramsGen.init(PBEParametersGenerator.PKCS5PasswordToBytes(password), salt, 1); KeyParameter kp = (KeyParameter)paramsGen.generateDerivedParameters(keyLength * 8); if (des2 && kp.getKey().length == 24) { // For DES2, we must copy first 8 bytes into the last 8 bytes. byte[] key = kp.getKey(); System.arraycopy(key, 0, key, 16, 8); return new KeyParameter(key); } return kp; } }
/** * Generate a key with initialisation vector parameter derived from * the password, salt, and iteration count we are currently initialised * with. * * @param keySize the size of the key we want (in bits) * @param ivSize the size of the iv we want (in bits) * @return a ParametersWithIV object. * @exception IllegalArgumentException if keySize + ivSize is larger than the base hash size. */ public CipherParameters generateDerivedParameters( int keySize, int ivSize) { keySize = keySize / 8; ivSize = ivSize / 8; byte[] dKey = generateDerivedKey(keySize + ivSize); return new ParametersWithIV(new KeyParameter(dKey, 0, keySize), dKey, keySize, ivSize); }
generator = new OpenSSLPBEParametersGenerator();
/** * Generate a key with initialisation vector parameter derived from * the password, salt, and iteration count we are currently initialised * with. * * @param keySize the size of the key we want (in bits) * @param ivSize the size of the iv we want (in bits) * @return a ParametersWithIV object. * @exception IllegalArgumentException if keySize + ivSize is larger than the base hash size. */ public CipherParameters generateDerivedParameters( int keySize, int ivSize) { keySize = keySize / 8; ivSize = ivSize / 8; byte[] dKey = generateDerivedKey(keySize + ivSize); return new ParametersWithIV(new KeyParameter(dKey, 0, keySize), dKey, keySize, ivSize); }
generator = new OpenSSLPBEParametersGenerator();