Examples of OpenSSLPBEParametersGenerator


Examples of org.bouncycastle.crypto.generators.OpenSSLPBEParametersGenerator

        Cipher c = cipher.getCipher();
        byte[] iv = new byte[c.getBlockSize()];
        random.nextBytes(iv);
        byte[] salt = new byte[8];
        System.arraycopy(iv, 0, salt, 0, 8);
        OpenSSLPBEParametersGenerator pGen = new OpenSSLPBEParametersGenerator();
        pGen.init(PBEParametersGenerator.PKCS5PasswordToBytes(passwd), salt);
        KeyParameter param = (KeyParameter) pGen.generateDerivedParameters(cipher.getKeyLenInBits());
        SecretKey secretKey = new SecretKeySpec(param.getKey(), org.jruby.ext.openssl.Cipher.Algorithm.getAlgorithmBase(c));
        byte[] encData = null;
        try {
            c.init(Cipher.ENCRYPT_MODE, secretKey, new IvParameterSpec(iv));
            encData = c.doFinal(encoding);
View Full Code Here

Examples of org.bouncycastle.crypto.generators.OpenSSLPBEParametersGenerator

        if (iv.length != ivLen) {
            throw new IOException("Illegal IV length");
        }
        byte[] salt = new byte[8];
        System.arraycopy(iv, 0, salt, 0, 8);
        OpenSSLPBEParametersGenerator pGen = new OpenSSLPBEParametersGenerator();
        pGen.init(PBEParametersGenerator.PKCS5PasswordToBytes(passwd), salt);
        KeyParameter param = (KeyParameter) pGen.generateDerivedParameters(keyLen * 8);
        SecretKey secretKey = new javax.crypto.spec.SecretKeySpec(param.getKey(), realName);
        Cipher c = Cipher.getInstance(realName);
        c.init(Cipher.DECRYPT_MODE, secretKey, new IvParameterSpec(iv));
        return c.doFinal(decoded);
    }
View Full Code Here

Examples of org.bouncycastle.crypto.generators.OpenSSLPBEParametersGenerator

        super(context);
    }

    @Override
    protected PBEParametersGenerator createPBEParametersGenerator() {
        return new OpenSSLPBEParametersGenerator();
    }
View Full Code Here

Examples of org.bouncycastle.crypto.generators.OpenSSLPBEParametersGenerator

        super.setIterationCount(1);
    }

    @Override
    protected PBEParametersGenerator createPBEParametersGenerator() {
        return new OpenSSLPBEParametersGenerator();
    }
View Full Code Here

Examples of org.bouncycastle2.crypto.generators.OpenSSLPBEParametersGenerator

                    throw new IllegalStateException("unknown digest scheme for PBE encryption.");
                }
            }
            else
            {
                generator = new OpenSSLPBEParametersGenerator();
            }
   
            return generator;
        }
View Full Code Here

Examples of org.bouncycastle2.crypto.generators.OpenSSLPBEParametersGenerator

        String  algorithm,
        int     keyLength,
        byte[]  salt,
        boolean des2)
    {
        OpenSSLPBEParametersGenerator   pGen = new OpenSSLPBEParametersGenerator();

        pGen.init(PBEParametersGenerator.PKCS5PasswordToBytes(password), salt);

        KeyParameter keyParam;
        keyParam = (KeyParameter) pGen.generateDerivedParameters(keyLength * 8);
        byte[] key = keyParam.getKey();
        if (des2 && key.length >= 24)
        {
            // For DES2, we must copy first 8 bytes into the last 8 bytes.
            System.arraycopy(key, 0, key, 16, 8);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.