Package org.bouncycastle.crypto.params

Examples of org.bouncycastle.crypto.params.KeyParameter


        int     inLen,
        byte[]  z)
        throws InvalidCipherTextException
    {
        byte[]          M = null;
        KeyParameter    macKey = null;
        KDFParameters   kParam = new KDFParameters(z, param.getDerivationV());
        int             macKeySize = param.getMacKeySize();

        kdf.init(kParam);

      inLen -= mac.getMacSize();
 
        if (cipher == null)     // stream mode
        {
            byte[]  buf = new byte[inLen + (macKeySize / 8)];

            M = new byte[inLen];

            kdf.generateBytes(buf, 0, buf.length);

            for (int i = 0; i != inLen; i++)
            {
                M[i] = (byte)(in_enc[inOff + i] ^ buf[i]);
            }

            macKey = new KeyParameter(buf, inLen, (macKeySize / 8));
        }
        else
        {
            int     cipherKeySize = ((IESWithCipherParameters)param).getCipherKeySize();
            byte[]  buf = new byte[(cipherKeySize / 8) + (macKeySize / 8)];

            cipher.init(false, new KeyParameter(buf, 0, (cipherKeySize / 8)));

            byte[] tmp = new byte[cipher.getOutputSize(inLen)];

            int off = cipher.processBytes(in_enc, inOff, inLen, tmp, 0);

            off += cipher.doFinal(tmp, off);

            M = new byte[off];

            System.arraycopy(tmp, 0, M, 0, off);

            macKey = new KeyParameter(buf, (cipherKeySize / 8), (macKeySize / 8));
        }

        byte[]  macIV = param.getEncodingV();

        mac.init(macKey);
View Full Code Here


        int     inLen,
        byte[]  z)
        throws InvalidCipherTextException
    {
        byte[]          C = null;
        KeyParameter    macKey = null;
        KDFParameters   kParam = new KDFParameters(z, param.getDerivationV());
      int             c_text_length = 0;
        int             macKeySize = param.getMacKeySize();

        kdf.init(kParam);

        if (cipher == null)     // stream mode
        {
            byte[]  buf = new byte[inLen + (macKeySize / 8)];

            C = new byte[inLen + mac.getMacSize()];
          c_text_length = inLen;

            kdf.generateBytes(buf, 0, buf.length);

            for (int i = 0; i != inLen; i++)
            {
                C[i] = (byte)(in[inOff + i] ^ buf[i]);
            }

            macKey = new KeyParameter(buf, inLen, (macKeySize / 8));
        }
        else
        {
            int     cipherKeySize = ((IESWithCipherParameters)param).getCipherKeySize();
            byte[]  buf = new byte[(cipherKeySize / 8) + (macKeySize / 8)];

            cipher.init(true, new KeyParameter(buf, 0, (cipherKeySize / 8)));

            c_text_length = cipher.getOutputSize(inLen);

            C = new byte[c_text_length + mac.getMacSize()];

            int off = cipher.processBytes(in, inOff, inLen, C, 0);

            cipher.doFinal(C, off);

            macKey = new KeyParameter(buf, (cipherKeySize / 8), (macKeySize / 8));
        }

        byte[]  macIV = param.getEncodingV();

        mac.init(macKey);
View Full Code Here

  getObfuscatedValue(
    byte[]    plain_key )
  {
        RC4Engine  engine = new RC4Engine();
       
    CipherParameters  params = new KeyParameter( new SHA1Simple().calculateHash( plain_key ));
   
    engine.init( true, params );

    byte[]  temp = new byte[1024];
   
View Full Code Here

  {
      SecretKeySpec  secret_key_spec = new SecretKeySpec( key, "RC4" );
     
      RC4Engine rc4_engine  = new RC4Engine();
   
    CipherParameters  params_a = new KeyParameter( secret_key_spec.getEncoded());
   
      // for RC4 enc/dec is irrelevant
   
    rc4_engine.init( true, params_a );
   
View Full Code Here

    {
        keySize = keySize / 8;

        byte[]  dKey = generateDerivedKey(KEY_MATERIAL, keySize);

        return new KeyParameter(dKey, 0, keySize);
    }
View Full Code Here

        byte[]  dKey = generateDerivedKey(KEY_MATERIAL, keySize);

        byte[]  iv = generateDerivedKey(IV_MATERIAL, ivSize);

        return new ParametersWithIV(new KeyParameter(dKey, 0, keySize), iv, 0, ivSize);
    }
View Full Code Here

    {
        keySize = keySize / 8;

        byte[]  dKey = generateDerivedKey(MAC_MATERIAL, keySize);

        return new KeyParameter(dKey, 0, keySize);
    }
View Full Code Here

       
        if ( internal_rc4 ){
                 
          rc4_engine  = new RC4Engine();
         
          CipherParameters  params = new KeyParameter(key_spec.getEncoded());
         
          rc4_engine.init( mode == Cipher.ENCRYPT_MODE, params );
        }
       
        //System.out.println( "RC4 key: " + ByteFormatter.encodeString( key_spec.getEncoded()));
View Full Code Here

        }

        /*
         * Prepare the f8Cipher with the special key to compute IV'
         */
        KeyParameter encryptionKey = new KeyParameter(maskedKey);
        f8Cipher.init(true, encryptionKey);
        /*
         * Use the masked key to encrypt the original IV to produce IV'.
         */
        f8Cipher.processBlock(iv, 0, f8ctx.ivAccent, 0);
View Full Code Here

         * Resets the cipher's key. This is done after every reseed, which combines
         * the old key and the seed, and processes that through the hash function.
         */
        private void resetKey() {
            cipher.reset();
            cipher.init(true, new KeyParameter(key));
        }
View Full Code Here

TOP

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

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.