|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.didisoft.pgp.net.HKPClient
public final class HKPClient
Retrieves keys from HTTP/S HKP key servers
Check for details: https://tools.ietf.org/html/draft-shaw-openpgp-hkp-00
Example usage:
import java.io.ByteArrayInputStream; import com.didisoft.pgp.net.HKPClient; import com.didisoft.pgp.KeyStore; public class DemoHKP { public static void demo() throws Exception { // connect to HKP key server HKPClient hkp = new HKPClient("pgp.mit.edu"); // search by part of the User Id hkp.setPartialMatchUserIds(true); byte[] keyBytes = hkp.getKeyByUserId("DidiSoft"); // String keyInAscii = new String(keyBytes, "ASCII"); if (keyBytes != null && keyBytes.length > 0) { KeyStore ks = new KeyStore(); ks.importKeyRing(new ByteArrayInputStream(keyBytes)); } else { System.out.println("no key found") } } }
Constructor Summary | |
---|---|
HKPClient(java.lang.String name)
creates a new istance |
|
HKPClient(java.lang.String name,
int port)
creates a new istance |
|
HKPClient(java.lang.String name,
int port,
boolean useHttps)
|
Method Summary | |
---|---|
byte[] |
getKeyByKeyId(long keyId)
Tries to retrieve a key from a HKP HTTP/S server searching by Key Id. |
byte[] |
getKeyByKeyIdHex(java.lang.String keyIdHex)
Tries to retrieve a key from a HKP HTTP/S server searching by hexadecimal Key Id. |
byte[] |
getKeyByUserId(java.lang.String userId)
Tries to retrieve a key from a HKP HTTP/S key server searching by User Id. |
byte[] |
getKeysByUserId(java.lang.String userId)
Tries to retrieve all keys from a HKP HTTP/S key server searching by User Id. |
java.lang.String |
getUserAgent()
Returns the User-Agent HTTP header that this class sends when communicates with HKP key servers |
boolean |
isPartialMatchUserIds()
Returns should keys be search by part of the User ID (true) or with the whole User ID only (false) |
void |
setPartialMatchUserIds(boolean partialMatch)
Sets should keys be search by part of the User ID (true) or with the whole User ID only (false) |
void |
setUserAgent(java.lang.String userAgent)
Sets the User-Agent HTTP header that this class sends when communicates with HKP key servers |
boolean |
submitKey(byte[] keyBytes)
Uploads an OpenPGP key bytes into a HKP HTTP key server |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public HKPClient(java.lang.String name)
name
- IP address or domain name of the HKP key serverpublic HKPClient(java.lang.String name, int port)
name
- IP address or domain name of the HKP key serverport
- port (usually 80)public HKPClient(java.lang.String name, int port, boolean useHttps)
Method Detail |
---|
public byte[] getKeyByKeyIdHex(java.lang.String keyIdHex) throws java.io.IOException
keyIdHex
- key Id in hexadecimal format (like "B29931AC")
java.io.IOException
- in case of a network connection problem
Example:
HKPClient hkp = new HKPClient("pgp.mit.edu", 80); byte[] keyBytes = hkp.getKeyByKeyIdHex("292AD653"); if (keyBytes.length > 0) { System.out.println(new String(keyBytes, "ASCII")); } else { System.out.println("key not fond"); }
public byte[] getKeyByUserId(java.lang.String userId) throws java.io.IOException
userId
- Whole or part of one of the User Id's of the key
java.io.IOException
- in case of a network connection problem
Example:
HKPClient hkp = new HKPClient("pgp.mit.edu", 80); byte[] keyBytes = hkp.getKeyByUserId("DidiSoft"); if (keyBytes.length > 0) { System.out.println(new String(keyBytes, "ASCII")); } else { System.out.println("key not fond"); }
public byte[] getKeysByUserId(java.lang.String userId) throws java.io.IOException
userId
- Whole or part of one of the User Id's of the key
java.io.IOException
- in case of a network connection problem
Example:
HKPClient hkp = new HKPClient("pgp.mit.edu", 80); byte[] keysBytes = hkp.getKeysByUserId("DidiSoft"); if (keyBytes.length > 0) { System.out.println(new String(keyBytes, "ASCII")); } else { System.out.println("key not fond"); } KeyStore ks = new KeyStore(); KeyPairInformation[] keys = ks.importPublicKey(keysBytes);
public byte[] getKeyByKeyId(long keyId) throws java.io.IOException
keyId
- key Id
java.io.IOException
- in case of a network connection problempublic boolean submitKey(byte[] keyBytes) throws java.lang.Exception
keyBytes
- OpenPGP key serialized as array of bytes
java.lang.Exception
- in case of an error
Example:
HKPClient hkp = new HKPClient("pgp.mit.edu", 80); java.io.FileInputStream fIn = new java.io.FileInputStream("c:\\Test\\new3\\silverpub.asc"); ByteArrayOutputStream bOut = new ByteArrayOutputStream(); int i = -1; while ((i = fIn.read()) != -1) { bOut.write(i); } boolean ok = hkp.submitKey(bOut.toByteArray());
public java.lang.String getUserAgent()
public void setUserAgent(java.lang.String userAgent)
userAgent
- User-Agent HTTP header valuepublic boolean isPartialMatchUserIds()
setPartialMatchUserIds(boolean)
public void setPartialMatchUserIds(boolean partialMatch)
partialMatch
- if true, User ID parameters can be specified with part of the User ID
when false the whole User ID must be specifiedisPartialMatchUserIds()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |