@Override protected byte[] encrypt(byte type,byte[] fragment,int offset,int len){
  try {
    int content_mac_length=len + hash_size;
    int padding_length=(block_size == 0) ? 0 : getPaddingSize(++content_mac_length);
    byte[] res=new byte[content_mac_length + padding_length];
    System.arraycopy(fragment,offset,res,0,len);
    mac_material_header[0]=type;
    mac_material_header[3]=(byte)((0x00FF00 & len) >> 8);
    mac_material_header[4]=(byte)(0x0000FF & len);
    encMac.update(write_seq_num);
    encMac.update(mac_material_header);
    encMac.update(fragment,offset,len);
    encMac.doFinal(res,len);
    if (block_size != 0) {
      Arrays.fill(res,content_mac_length - 1,res.length,(byte)(padding_length));
    }
    if (logger != null) {
      logger.println("SSLRecordProtocol.do_encryption: Generic" + (block_size != 0 ? "BlockCipher with padding[" + padding_length + "]:" : "StreamCipher:"));
      logger.print(res);
    }
    byte[] rez=new byte[encCipher.getOutputSize(res.length)];
    encCipher.update(res,0,res.length,rez);
    incSequenceNumber(write_seq_num);
    return rez;
  }
 catch (  GeneralSecurityException e) {
    e.printStackTrace();
    throw new AlertException(AlertProtocol.INTERNAL_ERROR,new SSLProtocolException("Error during the encryption"));
  }
}

@ Override protected byte [ ] encrypt ( byte type , byte [ ] fragment , int offset , int len ) { try { int content_mac_length = len + hash_size ; int padding_length = ( block_size == 0 ) ? 0 : getPaddingSize ( ++ content_mac_length ) ; byte [ ] res = new byte [ content_mac_length + padding_length ] ; System . arraycopy ( fragment , offset , res , 0 , len ) ; mac_material_header [ 0 ] = type ; mac_material_header [ 3 ] = ( byte ) ( ( 0x00FF00 & len ) > > 8 ) ; mac_material_header [ 4 ] = ( byte ) ( 0x0000FF & len ) ; encMac . update ( write_seq_num ) ; encMac . update ( mac_material_header ) ; encMac . update ( fragment , offset , len ) ; encMac . doFinal ( res , len ) ; if ( block_size != 0 ) { Arrays . fill ( res , content_mac_length - 1 , res . length , ( byte ) ( padding_length ) ) ; } if ( logger != null ) { logger . println ( "SSLRecordProtocol.do_encryption: Generic" + ( block_size != 0 ? "BlockCipher with padding[" + padding_length + "]:" : "StreamCipher:" ) ) ; logger . print ( res ) ; } byte [ ] rez = new byte [ encCipher . getOutputSize ( res . length ) ] ; encCipher . update ( res , 0 , res . length , rez ) ; incSequenceNumber ( write_seq_num ) ; return rez ; } catch ( GeneralSecurityException e ) { e . printStackTrace ( ) ; throw new AlertException ( AlertProtocol . INTERNAL_ERROR , new SSLProtocolException ( "Error during the encryption" ) ) ; } }
creates the genericstreamcipher or genericblockcipher data structure for specified data of specified type .
