{
  protected boolean verifySignature(final Object sig)      throws IllegalStateException  {    if (publicKey == null)      {        throw new IllegalStateException();      }    final byte[] S = (byte[]) sig;    // 1. Length checking: If the length of the signature S is not k octets,    //    output "invalid signature" and stop.    final int modBits = ((RSAPublicKey) publicKey).getModulus().bitLength();    final int k = (modBits + 7) / 8;    if (S.length != k)      {        return false;      }    // 2. RSA verification:    //    a. Convert the signature S to an integer signature representative    //       s (see Section 4.2): s = OS2IP (S).    final BigInteger s = new BigInteger(1, S);    //    b. Apply the RSAVP1 verification primitive (Section 5.2.2) to the    //       RSA public key (n, e) and the signature representative s to    //       produce an integer message representative m:    //          m = RSAVP1 ((n, e), s).    //       If RSAVP1 outputs "signature representative out of range,"    //       output "invalid signature" and stop.    final BigInteger m;    try      {        m = RSA.verify(publicKey, s);      }    catch (IllegalArgumentException x)      {        return false;      }    //    c. Convert the message representative m to an encoded message EM    //       of length k octets (see Section 4.1): EM = I2OSP (m, k).    //       If I2OSP outputs "integer too large," output "invalid signature"    //       and stop.    final byte[] EM;    try      {        EM = RSA.I2OSP(m, k);      }    catch (IllegalArgumentException x)      {        return false;      }    // 3. EMSA-PKCS1-v1_5 encoding: Apply the EMSA-PKCS1-v1_5 encoding    //    operation (Section 9.2) to the message M to produce a second    //    encoded message EM' of length k octets:    //       EM' = EMSA-PKCS1-V1_5-ENCODE (M, k).    //    If the encoding operation outputs "message too long," output    //    "message too long" and stop.  If the encoding operation outputs    //    "intended encoded message length too short," output "RSA modulus    //    too short" and stop.    final byte[] EMp = pkcs1.encode(md.digest(), k);    // 4. Compare the encoded message EM and the second encoded message EM'.    //    If they are the same, output "valid signature"; otherwise, output    //    "invalid signature."    return Arrays.equals(EM, EMp);  }