IKeyPairCodec kpc = KeyPairCodecFactory.getInstance(k); if (kpc == null) { throw new KeyAgreementException(""); } byte[] b = kpc.encodePublicKey(k); int length = b.length; if (length > Registry.SASL_FOUR_BYTE_MAX_LIMIT) { throw new KeyAgreementException("encoded public key is too long"); } byte[] lengthBytes = { (byte) (length >>> 24), (byte) (length >>> 16), (byte) (length >>> 8), (byte) length }; out.write(lengthBytes, 0, 4); out.write(b, 0, b.length);
writeKey(k);
  public void writePublicKey(PublicKey k) throws KeyAgreementException  {    IKeyPairCodec kpc = KeyPairCodecFactory.getInstance(k);    if (kpc == null)      {        throw new KeyAgreementException("");      }    byte[] b = kpc.encodePublicKey(k);    int length = b.length;    if (length > Registry.SASL_FOUR_BYTE_MAX_LIMIT)      {        throw new KeyAgreementException("encoded public key is too long");      }    byte[] lengthBytes = { (byte) (length >>> 24), (byte) (length >>> 16),                          (byte) (length >>> 8), (byte) length };    out.write(lengthBytes, 0, 4);    out.write(b, 0, b.length);  }