private void desCbcDecrypt(WrapToken token,byte[] key,InputStream is,int len,byte[] dataOutBuf,int dataOffset) throws GSSException, IOException {
  int temp=0;
  Cipher des=getInitializedDes(false,key,ZERO_IV);
  WrapTokenInputStream truncatedInputStream=new WrapTokenInputStream(is,len);
  CipherInputStream cis=new CipherInputStream(truncatedInputStream,des);
  temp=cis.read(token.confounder);
  len-=temp;
  int blockSize=des.getBlockSize();
  int numBlocks=len / blockSize - 1;
  for (int i=0; i < numBlocks; i++) {
    temp=cis.read(dataOutBuf,dataOffset,blockSize);
    dataOffset+=blockSize;
  }
  byte[] finalBlock=new byte[blockSize];
  temp=cis.read(finalBlock);
  try {
    des.doFinal();
  }
 catch (  GeneralSecurityException e) {
    GSSException ge=new GSSException(GSSException.FAILURE,-1,"Could not use DES cipher - " + e.getMessage());
    ge.initCause(e);
    throw ge;
  }
  int padSize=finalBlock[blockSize - 1];
  if (padSize < 1 || padSize > 8)   throw new GSSException(GSSException.DEFECTIVE_TOKEN,-1,"Invalid padding on Wrap Token");
  token.padding=WrapToken.pads[padSize];
  blockSize-=padSize;
  System.arraycopy(finalBlock,0,dataOutBuf,dataOffset,blockSize);
}

private void desCbcDecrypt ( WrapToken token , byte [ ] key , InputStream is , int len , byte [ ] dataOutBuf , int dataOffset ) throws GSSException , IOException { int temp = 0 ; Cipher des = getInitializedDes ( false , key , ZERO_IV ) ; WrapTokenInputStream truncatedInputStream = new WrapTokenInputStream ( is , len ) ; CipherInputStream cis = new CipherInputStream ( truncatedInputStream , des ) ; temp = cis . read ( token . confounder ) ; len -= temp ; int blockSize = des . getBlockSize ( ) ; int numBlocks = len / blockSize - 1 ; for ( int i = 0 ; i < numBlocks ; i ++ ) { temp = cis . read ( dataOutBuf , dataOffset , blockSize ) ; dataOffset += blockSize ; } byte [ ] finalBlock = new byte [ blockSize ] ; temp = cis . read ( finalBlock ) ; try { des . doFinal ( ) ; } catch ( GeneralSecurityException e ) { GSSException ge = new GSSException ( GSSException . FAILURE , - 1 , "Could not use DES cipher - " + e . getMessage ( ) ) ; ge . initCause ( e ) ; throw ge ; } int padSize = finalBlock [ blockSize - 1 ] ; if ( padSize < 1 || padSize > 8 ) throw new GSSException ( GSSException . DEFECTIVE_TOKEN , - 1 , "Invalid padding on Wrap Token" ) ; token . padding = WrapToken . pads [ padSize ] ; blockSize -= padSize ; System . arraycopy ( finalBlock , 0 , dataOutBuf , dataOffset , blockSize ) ; }
helper routine to decrypt from an inputstream and write the application data straight to an output array with minimal buffer copies . the confounder and the padding are stored separately and not copied into this output array .
