protected void encodePayload() throws IOException {
      String format = key.getFormat();
      if (key instanceof DSSPrivateKey) {
         properties.put("type", "RAW-DSS");
         IKeyPairCodec coder = KeyPairCodecFactory.getInstance("dss");
         payload = coder.encodePrivateKey((PrivateKey) key);
      } else if (key instanceof GnuRSAPrivateKey) {
         properties.put("type", "RAW-RSA");
         IKeyPairCodec coder = KeyPairCodecFactory.getInstance("rsa");
         payload = coder.encodePrivateKey((PrivateKey) key);
      } else if (key instanceof GnuDHPrivateKey) {
         properties.put("type", "RAW-DH");
         IKeyPairCodec coder = KeyPairCodecFactory.getInstance("dh");
         payload = coder.encodePrivateKey((PrivateKey) key);
      } else if (key instanceof GnuSecretKey) {
         properties.put("type", "RAW");
         payload = key.getEncoded();
      } else if (format != null && format.equals("PKCS#8")) {
         properties.put("type", "PKCS8");
         payload = key.getEncoded();
      } else {
         throw new IllegalArgumentException("unsupported private key");
      }
   }