public boolean verifySignature(byte[] signature){
  byte[] block=null;
  if (preSig == null) {
    try {
      block=cipher.processBlock(signature,0,signature.length);
    }
 catch (    Exception e) {
      return false;
    }
  }
 else {
    if (!Arrays.areEqual(preSig,signature)) {
      throw new IllegalStateException("updateWithRecoveredMessage called on different signature");
    }
    block=preBlock;
    preSig=null;
    preBlock=null;
  }
  if (((block[0] & 0xC0) ^ 0x40) != 0) {
    return returnFalse(block);
  }
  if (((block[block.length - 1] & 0xF) ^ 0xC) != 0) {
    return returnFalse(block);
  }
  int delta=0;
  if (((block[block.length - 1] & 0xFF) ^ 0xBC) == 0) {
    delta=1;
  }
 else {
    int sigTrail=((block[block.length - 2] & 0xFF) << 8) | (block[block.length - 1] & 0xFF);
    Integer trailerObj=(Integer)trailerMap.get(digest.getAlgorithmName());
    if (trailerObj != null) {
      if (sigTrail != trailerObj.intValue()) {
        throw new IllegalStateException("signer initialised with wrong digest for trailer " + sigTrail);
      }
    }
 else {
      throw new IllegalArgumentException("unrecognised hash in signature");
    }
    delta=2;
  }
  int mStart=0;
  for (mStart=0; mStart != block.length; mStart++) {
    if (((block[mStart] & 0x0f) ^ 0x0a) == 0) {
      break;
    }
  }
  mStart++;
  byte[] hash=new byte[digest.getDigestSize()];
  int off=block.length - delta - hash.length;
  if ((off - mStart) <= 0) {
    return returnFalse(block);
  }
  if ((block[0] & 0x20) == 0) {
    fullMessage=true;
    if (messageLength > off - mStart) {
      return returnFalse(block);
    }
    digest.reset();
    digest.update(block,mStart,off - mStart);
    digest.doFinal(hash,0);
    boolean isOkay=true;
    for (int i=0; i != hash.length; i++) {
      block[off + i]^=hash[i];
      if (block[off + i] != 0) {
        isOkay=false;
      }
    }
    if (!isOkay) {
      return returnFalse(block);
    }
    recoveredMessage=new byte[off - mStart];
    System.arraycopy(block,mStart,recoveredMessage,0,recoveredMessage.length);
  }
 else {
    fullMessage=false;
    digest.doFinal(hash,0);
    boolean isOkay=true;
    for (int i=0; i != hash.length; i++) {
      block[off + i]^=hash[i];
      if (block[off + i] != 0) {
        isOkay=false;
      }
    }
    if (!isOkay) {
      return returnFalse(block);
    }
    recoveredMessage=new byte[off - mStart];
    System.arraycopy(block,mStart,recoveredMessage,0,recoveredMessage.length);
  }
  if (messageLength != 0) {
    if (!isSameAs(mBuf,recoveredMessage)) {
      return returnFalse(block);
    }
  }
  clearBlock(mBuf);
  clearBlock(block);
  return true;
}

public boolean verifySignature ( byte [ ] signature ) { byte [ ] block = null ; if ( preSig == null ) { try { block = cipher . processBlock ( signature , 0 , signature . length ) ; } catch ( Exception e ) { return false ; } } else { if ( ! Arrays . areEqual ( preSig , signature ) ) { throw new IllegalStateException ( "updateWithRecoveredMessage called on different signature" ) ; } block = preBlock ; preSig = null ; preBlock = null ; } if ( ( ( block [ 0 ] & 0xC0 ) ^ 0x40 ) != 0 ) { return returnFalse ( block ) ; } if ( ( ( block [ block . length - 1 ] & 0xF ) ^ 0xC ) != 0 ) { return returnFalse ( block ) ; } int delta = 0 ; if ( ( ( block [ block . length - 1 ] & 0xFF ) ^ 0xBC ) == 0 ) { delta = 1 ; } else { int sigTrail = ( ( block [ block . length - 2 ] & 0xFF ) << 8 ) | ( block [ block . length - 1 ] & 0xFF ) ; Integer trailerObj = ( Integer ) trailerMap . get ( digest . getAlgorithmName ( ) ) ; if ( trailerObj != null ) { if ( sigTrail != trailerObj . intValue ( ) ) { throw new IllegalStateException ( "signer initialised with wrong digest for trailer " + sigTrail ) ; } } else { throw new IllegalArgumentException ( "unrecognised hash in signature" ) ; } delta = 2 ; } int mStart = 0 ; for ( mStart = 0 ; mStart != block . length ; mStart ++ ) { if ( ( ( block [ mStart ] & 0x0f ) ^ 0x0a ) == 0 ) { break ; } } mStart ++ ; byte [ ] hash = new byte [ digest . getDigestSize ( ) ] ; int off = block . length - delta - hash . length ; if ( ( off - mStart ) <= 0 ) { return returnFalse ( block ) ; } if ( ( block [ 0 ] & 0x20 ) == 0 ) { fullMessage = true ; if ( messageLength > off - mStart ) { return returnFalse ( block ) ; } digest . reset ( ) ; digest . update ( block , mStart , off - mStart ) ; digest . doFinal ( hash , 0 ) ; boolean isOkay = true ; for ( int i = 0 ; i != hash . length ; i ++ ) { block [ off + i ] ^= hash [ i ] ; if ( block [ off + i ] != 0 ) { isOkay = false ; } } if ( ! isOkay ) { return returnFalse ( block ) ; } recoveredMessage = new byte [ off - mStart ] ; System . arraycopy ( block , mStart , recoveredMessage , 0 , recoveredMessage . length ) ; } else { fullMessage = false ; digest . doFinal ( hash , 0 ) ; boolean isOkay = true ; for ( int i = 0 ; i != hash . length ; i ++ ) { block [ off + i ] ^= hash [ i ] ; if ( block [ off + i ] != 0 ) { isOkay = false ; } } if ( ! isOkay ) { return returnFalse ( block ) ; } recoveredMessage = new byte [ off - mStart ] ; System . arraycopy ( block , mStart , recoveredMessage , 0 , recoveredMessage . length ) ; } if ( messageLength != 0 ) { if ( ! isSameAs ( mBuf , recoveredMessage ) ) { return returnFalse ( block ) ; } } clearBlock ( mBuf ) ; clearBlock ( block ) ; return true ; }
return true if the signature represents a iso9796 - 2 signature for the passed in message .
