private CipherBox(ProtocolVersion protocolVersion,BulkCipher bulkCipher,SecretKey key,IvParameterSpec iv,SecureRandom random,boolean encrypt) throws NoSuchAlgorithmException {
  try {
    this.protocolVersion=protocolVersion;
    this.cipher=JsseJce.getCipher(bulkCipher.transformation);
    this.mode=encrypt ? Cipher.ENCRYPT_MODE : Cipher.DECRYPT_MODE;
    if (random == null) {
      random=JsseJce.getSecureRandom();
    }
    this.random=random;
    this.cipherType=bulkCipher.cipherType;
    if (iv == null && bulkCipher.ivSize != 0 && mode == Cipher.DECRYPT_MODE && protocolVersion.v >= ProtocolVersion.TLS11.v) {
      iv=getFixedMask(bulkCipher.ivSize);
    }
    if (cipherType == AEAD_CIPHER) {
      tagSize=bulkCipher.tagSize;
      this.key=key;
      fixedIv=iv.getIV();
      if (fixedIv == null || fixedIv.length != bulkCipher.fixedIvSize) {
        throw new RuntimeException("Improper fixed IV for AEAD");
      }
      recordIvSize=bulkCipher.ivSize - bulkCipher.fixedIvSize;
    }
 else {
      this.tagSize=0;
      this.fixedIv=new byte[0];
      this.recordIvSize=0;
      this.key=null;
      cipher.init(mode,key,iv,random);
    }
  }
 catch (  NoSuchAlgorithmException e) {
    throw e;
  }
catch (  Exception e) {
    throw new NoSuchAlgorithmException("Could not create cipher " + bulkCipher,e);
  }
catch (  ExceptionInInitializerError e) {
    throw new NoSuchAlgorithmException("Could not create cipher " + bulkCipher,e);
  }
}

private CipherBox ( ProtocolVersion protocolVersion , BulkCipher bulkCipher , SecretKey key , IvParameterSpec iv , SecureRandom random , boolean encrypt ) throws NoSuchAlgorithmException { try { this . protocolVersion = protocolVersion ; this . cipher = JsseJce . getCipher ( bulkCipher . transformation ) ; this . mode = encrypt ? Cipher . ENCRYPT_MODE : Cipher . DECRYPT_MODE ; if ( random == null ) { random = JsseJce . getSecureRandom ( ) ; } this . random = random ; this . cipherType = bulkCipher . cipherType ; if ( iv == null && bulkCipher . ivSize != 0 && mode == Cipher . DECRYPT_MODE && protocolVersion . v >= ProtocolVersion . TLS11 . v ) { iv = getFixedMask ( bulkCipher . ivSize ) ; } if ( cipherType == AEAD_CIPHER ) { tagSize = bulkCipher . tagSize ; this . key = key ; fixedIv = iv . getIV ( ) ; if ( fixedIv == null || fixedIv . length != bulkCipher . fixedIvSize ) { throw new RuntimeException ( "Improper fixed IV for AEAD" ) ; } recordIvSize = bulkCipher . ivSize - bulkCipher . fixedIvSize ; } else { this . tagSize = 0 ; this . fixedIv = new byte [ 0 ] ; this . recordIvSize = 0 ; this . key = null ; cipher . init ( mode , key , iv , random ) ; } } catch ( NoSuchAlgorithmException e ) { throw e ; } catch ( Exception e ) { throw new NoSuchAlgorithmException ( "Could not create cipher " + bulkCipher , e ) ; } catch ( ExceptionInInitializerError e ) { throw new NoSuchAlgorithmException ( "Could not create cipher " + bulkCipher , e ) ; } }
construct a new cipherbox using the cipher transformation .
