Search in sources :

Example 1 with OpenSSLPBEParametersGenerator

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;
}
Also used : KeyParameter(com.github.zhenwei.core.crypto.params.KeyParameter) OpenSSLPBEParametersGenerator(com.github.zhenwei.core.crypto.generators.OpenSSLPBEParametersGenerator) PBEParametersGenerator(com.github.zhenwei.core.crypto.PBEParametersGenerator) OpenSSLPBEParametersGenerator(com.github.zhenwei.core.crypto.generators.OpenSSLPBEParametersGenerator)

Aggregations

PBEParametersGenerator (com.github.zhenwei.core.crypto.PBEParametersGenerator)1 OpenSSLPBEParametersGenerator (com.github.zhenwei.core.crypto.generators.OpenSSLPBEParametersGenerator)1 KeyParameter (com.github.zhenwei.core.crypto.params.KeyParameter)1