Examples of PKCS5S2ParametersGenerator


Examples of org.bouncycastle.crypto.generators.PKCS5S2ParametersGenerator

                    throw new IllegalStateException("PKCS5 scheme 1 only supports only MD5 and SHA1.");
                }
            }
            else if (type == PKCS5S2)
            {
                generator = new PKCS5S2ParametersGenerator();
            }
            else if (type == OLD_PKCS12)
            {
                switch (hash)
                {
View Full Code Here

Examples of org.bouncycastle.crypto.generators.PKCS5S2ParametersGenerator

                    throw new IllegalStateException("PKCS5 scheme 1 only supports MD2, MD5 and SHA1.");
                }
            }
            else if (type == PKCS5S2 || type == PKCS5S2_UTF8)
            {
                generator = new PKCS5S2ParametersGenerator();
            }
            else if (type == PKCS12)
            {
                switch (hash)
                {
View Full Code Here

Examples of org.bouncycastle.crypto.generators.PKCS5S2ParametersGenerator

                    throw new IllegalStateException("PKCS5 scheme 1 only supports MD2, MD5 and SHA1.");
                }
            }
            else if (type == PKCS5S2)
            {
                generator = new PKCS5S2ParametersGenerator();
            }
            else if (type == PKCS12)
            {
                switch (hash)
                {
View Full Code Here

Examples of org.bouncycastle.crypto.generators.PKCS5S2ParametersGenerator

        }

        public TestResult perform()
        {
            char[]                  password = { 'p', 'a', 's', 's', 'w', 'o', 'r', 'd' };
            PBEParametersGenerator  generator = new PKCS5S2ParametersGenerator();
            ByteArrayInputStream    bIn = new ByteArrayInputStream(sample);
            ASN1InputStream         dIn = new ASN1InputStream(bIn);
            EncryptedPrivateKeyInfo info;

            try
            {
                info = new EncryptedPrivateKeyInfo((ASN1Sequence)dIn.readObject());
            }
            catch (Exception e)
            {
                return new SimpleTestResult(false, getName() + ": failed construction - exception " + e.toString());
            }

            PBES2Parameters         alg = new PBES2Parameters((ASN1Sequence)info.getEncryptionAlgorithm().getParameters());
            PBKDF2Params            func = PBKDF2Params.getInstance(alg.getKeyDerivationFunc().getParameters());
            EncryptionScheme        scheme = alg.getEncryptionScheme();
   
            if (func.getKeyLength() != null)
            {
                keySize = func.getKeyLength().intValue() * 8;
            }
   
            int     iterationCount = func.getIterationCount().intValue();
            byte[]  salt = func.getSalt();
   
            generator.init(
                PBEParametersGenerator.PKCS5PasswordToBytes(password),
                salt,
                iterationCount);
   
            CipherParameters    param;
   
            if (scheme.getObjectId().equals(RC2_CBC))
            {
                RC2CBCParameter rc2Params = new RC2CBCParameter((ASN1Sequence)scheme.getObject());
                byte[]  iv = rc2Params.getIV();
   
                param = new ParametersWithIV(generator.generateDerivedParameters(keySize), iv);
            }
            else
            {
                byte[]  iv = ((ASN1OctetString)scheme.getObject()).getOctets();

                param = new ParametersWithIV(generator.generateDerivedParameters(keySize), iv);
            }
   
            cipher.init(false, param);
   
            byte[]  data = info.getEncryptedData();
View Full Code Here

Examples of org.bouncycastle.crypto.generators.PKCS5S2ParametersGenerator

                    throw new IllegalStateException("PKCS5 scheme 1 only supports only MD5 and SHA1.");
                }
            }
            else if (type == PKCS5S2)
            {
                generator = new PKCS5S2ParametersGenerator();
            }
            else if (type == PKCS12)
            {
                switch (hash)
                {
View Full Code Here

Examples of org.bouncycastle.crypto.generators.PKCS5S2ParametersGenerator

                    throw new IllegalStateException("PKCS5 scheme 1 only supports only MD5 and SHA1.");
                }
            }
            else if (type == PKCS5S2)
            {
                generator = new PKCS5S2ParametersGenerator();
            }
            else if (type == OLD_PKCS12)
            {
                switch (hash)
                {
View Full Code Here

Examples of org.bouncycastle.crypto.generators.PKCS5S2ParametersGenerator

        if (pbkdfParams.getKeyLength() != null) {
            keySize = pbkdfParams.getKeyLength().intValue() * 8;
        }
        int iterationCount = pbkdfParams.getIterationCount().intValue();
        byte[] salt = pbkdfParams.getSalt();
        PBEParametersGenerator generator = new PKCS5S2ParametersGenerator();
        generator.init(PBEParametersGenerator.PKCS5PasswordToBytes(password), salt, iterationCount);
        return generator.generateDerivedParameters(keySize);
    }
View Full Code Here

Examples of org.bouncycastle.crypto.generators.PKCS5S2ParametersGenerator

public class AESDecrypterBC extends AESCryptoBase implements AESDecrypter {

  public AESDecrypterBC( byte[] pwBytes, byte[] salt, byte[] pwVerification ) throws ZipException {
    super.saltBytes = salt;

    PBEParametersGenerator generator = new PKCS5S2ParametersGenerator();
    generator.init( pwBytes, salt, ITERATION_COUNT );

    cipherParameters = generator.generateDerivedParameters(KEY_SIZE_BIT*2 + 16);
    byte[] keyBytes = ((KeyParameter)cipherParameters).getKey();

    this.cryptoKeyBytes = new byte[ KEY_SIZE_BYTE ];
    System.arraycopy( keyBytes, 0, cryptoKeyBytes, 0, KEY_SIZE_BYTE );

    this.authenticationCodeBytes = new byte[ KEY_SIZE_BYTE ];
    System.arraycopy( keyBytes, KEY_SIZE_BYTE, authenticationCodeBytes, 0, KEY_SIZE_BYTE );

    // based on SALT + PASSWORD (password is probably correct)
    this.pwVerificationBytes = new byte[ 2 ];
    System.arraycopy( keyBytes, KEY_SIZE_BYTE*2, this.pwVerificationBytes, 0, 2 );

    if( !ByteArrayHelper.isEqual( this.pwVerificationBytes, pwVerification ) ) {
      throw new ZipException("wrong password - " + ByteArrayHelper.toString(this.pwVerificationBytes) + "/ " + ByteArrayHelper.toString(pwVerification));
    }

    // create the first 16 bytes of the key sequence again (using pw+salt)
    generator.init( pwBytes, salt, ITERATION_COUNT );
    cipherParameters = generator.generateDerivedParameters(KEY_SIZE_BIT);

    // checksum added to the end of the encrypted data, update on each encryption call
    this.mac = new HMac( new SHA1Digest() );
    mac.init( new KeyParameter(authenticationCodeBytes) );

View Full Code Here

Examples of org.bouncycastle.crypto.generators.PKCS5S2ParametersGenerator

  /**
   * Setup AES encryption based on pwBytes using WinZipAES approach
   * with SALT and pwVerification bytes based on password+salt.
   */
  public AESEncrypterBC( byte[] pwBytes ) throws ZipException {
    PBEParametersGenerator generator = new PKCS5S2ParametersGenerator();
    this.saltBytes = createSalt();
    generator.init( pwBytes, saltBytes, ITERATION_COUNT );

    // create 2 byte[16] for two keys and one byte[2] for pwVerification
    // 1. encryption / 2. athentication (via HMAC/hash) /
    cipherParameters = generator.generateDerivedParameters(KEY_SIZE_BIT*2 + 16);
    byte[] keyBytes = ((KeyParameter)cipherParameters).getKey();

    this.cryptoKeyBytes = new byte[ KEY_SIZE_BYTE ];
    System.arraycopy( keyBytes, 0, cryptoKeyBytes, 0, KEY_SIZE_BYTE );

    this.authenticationCodeBytes = new byte[ KEY_SIZE_BYTE ];
    System.arraycopy( keyBytes, KEY_SIZE_BYTE, authenticationCodeBytes, 0, KEY_SIZE_BYTE );

    // based on SALT + PASSWORD (password is probably correct)
    this.pwVerificationBytes = new byte[ 2 ];
    System.arraycopy( keyBytes, KEY_SIZE_BYTE*2, pwVerificationBytes, 0, 2 );

    // create the first 16 bytes of the key sequence again (using pw+salt)
    generator.init( pwBytes, saltBytes, ITERATION_COUNT );
    cipherParameters = generator.generateDerivedParameters(KEY_SIZE_BIT);

    // checksum added to the end of the encrypted data, update on each encryption call
    this.mac = new HMac( new SHA1Digest() );
    mac.init( new KeyParameter(authenticationCodeBytes) );

View Full Code Here

Examples of org.bouncycastle.crypto.generators.PKCS5S2ParametersGenerator

        super(password, salt, iterationCount);
    }

    byte[] getEncoded(String algorithmOid)
    {
        PKCS5S2ParametersGenerator gen = new PKCS5S2ParametersGenerator();

        gen.init(PBEParametersGenerator.PKCS5PasswordToBytes(this.getPassword()), this.getSalt(), this.getIterationCount());

        return ((KeyParameter)gen.generateDerivedParameters(CMSEnvelopedHelper.INSTANCE.getKeySize(algorithmOid))).getKey();
    }
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.