{
  public byte[] encode(final byte[] mHash, final int emLen)  {    // 1. Apply the hash function to the message M to produce a hash value    //    H: H = Hash(M).    //    If the hash function outputs "message too long," output "message    //    too long" and stop.    // 2. Encode the algorithm ID for the hash function and the hash value    //    into an ASN.1 value of type DigestInfo (see Appendix A.2.4) with    //    the Distinguished Encoding Rules (DER), where the type DigestInfo    //    has the syntax    //       DigestInfo ::= SEQUENCE {    //          digestAlgorithm AlgorithmIdentifier,    //          digest OCTET STRING    //       }    //   The first field identifies the hash function and the second contains    //   the hash value.  Let T be the DER encoding of the DigestInfo value    //   (see the notes below) and let tLen be the length in octets of T.    final ByteArrayOutputStream baos = new ByteArrayOutputStream();    baos.write(prefix, 0, prefix.length);    baos.write(mHash, 0, mHash.length);    final byte[] T = baos.toByteArray();    final int tLen = T.length;    // 3. If emLen < tLen + 11, output "intended encoded message length too    //    short" and stop.    if (emLen < tLen + 11)      {        throw new IllegalArgumentException("emLen too short");      }    // 4. Generate an octet string PS consisting of emLen - tLen - 3 octets    //    with hexadecimal value 0xff.  The length of PS will be at least 8    //    octets.    final byte[] PS = new byte[emLen - tLen - 3];    for (int i = 0; i < PS.length; i++)      {        PS[i] = (byte) 0xFF;      }    // 5. Concatenate PS, the DER encoding T, and other padding to form the    //    encoded message EM as: EM = 0x00 || 0x01 || PS || 0x00 || T.    baos.reset();    baos.write(0x00);    baos.write(0x01);    baos.write(PS, 0, PS.length);    baos.write(0x00);    baos.write(T, 0, tLen);    final byte[] result = baos.toByteArray();    baos.reset();    // 6. Output EM.    return result;  }