Package org.bouncycastle.crypto.params

Examples of org.bouncycastle.crypto.params.ParametersWithIV


      }
      */

      // Decrypt the cipher text with TRIPLedeS in CBC mode using the KEK
      // and an initialization vector (IV) of 0x4adda22c79e82105. Call the output TEMP3.
      ParametersWithIV param2 = new ParametersWithIV(this.param, IV2);

      this.engine.init(false, param2);

      byte TEMP3[] = new byte[inLen];

      System.arraycopy(in, inOff, TEMP3, 0, inLen);

      for (int i = 0; i < (TEMP3.length / engine.getBlockSize()); i++) {
         int currentBytePos = i * engine.getBlockSize();

         engine.processBlock(TEMP3, currentBytePos, TEMP3, currentBytePos);
      }

      // Reverse the order of the octets in TEMP3 and call the result TEMP2.
      byte[] TEMP2 = new byte[TEMP3.length];

      for (int i = 0; i < TEMP3.length; i++) {
         TEMP2[i] = TEMP3[TEMP3.length - (i + 1)];
      }

      // Decompose TEMP2 into IV, the first 8 octets, and TEMP1, the remaining octets.
      this.iv = new byte[8];

      byte[] TEMP1 = new byte[TEMP2.length - 8];

      System.arraycopy(TEMP2, 0, this.iv, 0, 8);
      System.arraycopy(TEMP2, 8, TEMP1, 0, TEMP2.length - 8);

      // Decrypt TEMP1 using TRIPLedeS in CBC mode using the KEK and the IV
      // found in the previous step. Call the result WKCKS.
      this.paramPlusIV = new ParametersWithIV(this.param, this.iv);

      this.engine.init(false, this.paramPlusIV);

      byte[] WKCKS = new byte[TEMP1.length];

View Full Code Here


    {
        this.forEncryption = forEncryption;
    
        if (params instanceof ParametersWithIV)
        {
                ParametersWithIV ivParam = (ParametersWithIV)params;
                byte[]      iv = ivParam.getIV();

                if (iv.length < IV.length)
                {
                    // prepend the supplied IV with zeros (per FIPS PUB 81)
                    System.arraycopy(iv, 0, IV, IV.length - iv.length, iv.length);
                    for (int i = 0; i < IV.length - iv.length; i++)
                    {
                            IV[i] = 0;
                    }
                }
                else
                {
                    System.arraycopy(iv, 0, IV, 0, IV.length);
                }

                reset();

                cipher.init(true, ivParam.getParameters());
        }
        else
        {
                reset();
View Full Code Here

        generator.init(
                PBEParametersGenerator.PKCS12PasswordToBytes(password),
                salt,
                iCount);

        ParametersWithIV params = (ParametersWithIV)generator.generateDerivedParameters(64, 64);

        if (isEqual(result, params.getIV()))
        {
            return new SimpleTestResult(true, "PKCS12Test: Okay");
        }
        else
        {
View Full Code Here

    public void init(boolean forEncryption, CipherParameters params)
          throws IllegalArgumentException {
        this.encrypting = forEncryption;

        if (params instanceof ParametersWithIV) {
          ParametersWithIV ivParam = (ParametersWithIV)params;
          byte[]           iv      = ivParam.getIV();
          System.arraycopy(iv, 0, IV, 0, IV.length);

          reset();
          cipher.init(true, ivParam.getParameters());
        }
    }
View Full Code Here

            SecureRandom sr = new SecureRandom();

            sr.nextBytes(iv);

            this.paramPlusIV = new ParametersWithIV(this.param, this.iv);
         }
      } else if (param instanceof ParametersWithIV) {
         this.paramPlusIV = (ParametersWithIV) param;
         this.iv = this.paramPlusIV.getIV();
         this.param = (KeyParameter) this.paramPlusIV.getParameters();
View Full Code Here

      }

      // Encrypt TEMP3 in CBC mode using the KEK and an initialization vector
      // of 0x 4a dd a2 2c 79 e8 21 05. The resulting cipher text is the desired
      // result. It is 40 octets long if a 168 bit key is being wrapped.
      ParametersWithIV param2 = new ParametersWithIV(this.param, IV2);

      this.engine.init(true, param2);

      for (int i = 0; i < noOfBlocks + 1; i++) {
         int currentBytePos = i * engine.getBlockSize();
 
View Full Code Here

      }
      */

      // Decrypt the cipher text with TRIPLedeS in CBC mode using the KEK
      // and an initialization vector (IV) of 0x4adda22c79e82105. Call the output TEMP3.
      ParametersWithIV param2 = new ParametersWithIV(this.param, IV2);

      this.engine.init(false, param2);

      byte TEMP3[] = new byte[inLen];

      System.arraycopy(in, inOff, TEMP3, 0, inLen);

      for (int i = 0; i < (TEMP3.length / engine.getBlockSize()); i++) {
         int currentBytePos = i * engine.getBlockSize();

         engine.processBlock(TEMP3, currentBytePos, TEMP3, currentBytePos);
      }

      // Reverse the order of the octets in TEMP3 and call the result TEMP2.
      byte[] TEMP2 = new byte[TEMP3.length];

      for (int i = 0; i < TEMP3.length; i++) {
         TEMP2[i] = TEMP3[TEMP3.length - (i + 1)];
      }

      // Decompose TEMP2 into IV, the first 8 octets, and TEMP1, the remaining octets.
      this.iv = new byte[8];

      byte[] TEMP1 = new byte[TEMP2.length - 8];

      System.arraycopy(TEMP2, 0, this.iv, 0, 8);
      System.arraycopy(TEMP2, 8, TEMP1, 0, TEMP2.length - 8);

      // Decrypt TEMP1 using TRIPLedeS in CBC mode using the KEK and the IV
      // found in the previous step. Call the result WKCKS.
      this.paramPlusIV = new ParametersWithIV(this.param, this.iv);

      this.engine.init(false, this.paramPlusIV);

      byte[] LCEKPADICV = new byte[TEMP1.length];

View Full Code Here

      System.arraycopy(key, 0, tmp, 0, tmp.length);
      key=tmp;
    }
    try{
      cipher=new CBCBlockCipher(new BlowfishEngine());
      CipherParameters param=new ParametersWithIV(new KeyParameter(key), iv);
      if(mode==ENCRYPT_MODE){ cipher.init(true, param); }
      else{ cipher.init(false, param); }
    }
    catch(Exception e){
      System.out.println(e);
View Full Code Here

      System.arraycopy(key, 0, tmp, 0, tmp.length);
      key=tmp;
    }
    try{
      cipher=new CBCBlockCipher(new DESedeEngine());
      CipherParameters param=new ParametersWithIV(new KeyParameter(key), iv);

      if(mode==ENCRYPT_MODE){ cipher.init(true, param); }
      else{ cipher.init(false, param); }
    }
    catch(Exception e){
View Full Code Here

        {
            throw new IllegalArgumentException(
                "Grain-128 Init parameters must include an IV");
        }

        ParametersWithIV ivParams = (ParametersWithIV)params;

        byte[] iv = ivParams.getIV();

        if (iv == null || iv.length != 12)
        {
            throw new IllegalArgumentException(
                "Grain-128  requires exactly 12 bytes of IV");
        }

        if (!(ivParams.getParameters() instanceof KeyParameter))
        {
            throw new IllegalArgumentException(
                "Grain-128 Init parameters must include a key");
        }

        KeyParameter key = (KeyParameter)ivParams.getParameters();

        /**
         * Initialize variables.
         */
        workingIV = new byte[key.getKey().length];
View Full Code Here

TOP

Related Classes of org.bouncycastle.crypto.params.ParametersWithIV

Copyright © 2018 www.massapicom. 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.