code: public static Record
  buildRecord(Name name, int type, int dclass, long ttl, int flags, int proto,
  	    int alg, PublicKey key)
  {
  	byte [] data;
  
  	if (type != Type.KEY && type != Type.DNSKEY)
  		throw new IllegalArgumentException("type must be KEY " +
  						   "or DNSKEY");
  
  	if (key instanceof RSAPublicKey) {
  		data = buildRSA((RSAPublicKey) key);
  	}
  	else if (key instanceof DHPublicKey) {
  		data = buildDH((DHPublicKey) key);
  	}
  	else if (key instanceof DSAPublicKey) {
  		data = buildDSA((DSAPublicKey) key);
  	}
  	else
  		return null;
  
  	if (data == null)
  		return null;
  
  	if (type == Type.DNSKEY)
  		return new DNSKEYRecord(name, dclass, ttl, flags, proto, alg,
  					data);
  	else
  		return new KEYRecord(name, dclass, ttl, flags, proto, alg,
  				     data);
  }
docs: Builds a DNSKEY or KEY record from a PublicKey