public byte[] decode(final byte[] EM) {
      // Separate the encoded message EM into an
      // octet string PS consisting of nonzero octets and a message M as
      //
      // EM = 0x00 || 0x02 || PS || 0x00 || M.
      //
      // If the first octet of EM does not have hexadecimal value 0x00, if
      // the second octet of EM does not have hexadecimal value 0x02, if
      // there is no octet with hexadecimal value 0x00 to separate PS from
      // M, or if the length of PS is less than 8 octets, output
      // "decryption error" and stop.  (See the note below.)
      final int emLen = EM.length;
      if (emLen != k) {
         throw new IllegalArgumentException("decryption error");
      }
      if (EM[0] != 0x00) {
         throw new IllegalArgumentException("decryption error");
      }
      if (EM[1] != 0x02) {
         throw new IllegalArgumentException("decryption error");
      }
      int i = 2;
      for ( ; i < emLen; i++) {
         if (EM[i] == 0x00) {
            break;
         }
      }
      if (i >= emLen || i < 11) {
         throw new IllegalArgumentException("decryption error");
      }
      i++;
      final byte[] result = new byte[emLen - i];
      System.arraycopy(EM, i, result, 0, result.length);
      return result;
   }