use of com.github.zhenwei.core.crypto.generators.OpenSSLPBEParametersGenerator in project LinLong-Java by zhenwei1108.
the class PEMUtilities method getKey.
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;
}
Aggregations