|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectezvcard.property.VCardProperty
ezvcard.property.BinaryProperty<KeyType>
ezvcard.property.Key
public class Key
A public key for encryption.
Adding a key
VCard vcard = new VCard();
//URL (vCard 4.0 only; KEYs cannot have URLs in vCard 2.1 and 3.0)
Key key = new Key("http://www.mywebsite.com/pubkey.pgp", KeyType.PGP);
vcard.addKey(key);
//binary data
byte data[] = ...
key = new Key(data, KeyType.PGP);
vcard.addKey(key);
//plain text value
key = new Key();
key.setText("...", KeyType.PGP);
vcard.addKey(key);
//if "KeyType" does not have the pre-defined constant that you need, then create a new instance
//arg 1: the value of the 2.1/3.0 TYPE parameter
//arg 2: the value to use for the 4.0 MEDIATYPE parameter and for 4.0 data URIs
//arg 3: the file extension of the data type (optional)
KeyType param = new KeyType("mykey", "application/my-key", "mkey");
key = new Key("http://www.mywebsite.com/pubkey.enc", param);
vcard.addKey(key);
Getting the keys
VCard vcard = ...
int fileCount = 0;
for (Key key : vcard.getKeys()){
//the key will have either a URL or a binary data
//only 4.0 vCards are allowed to use URLs for keys
if (key.getData() == null){
System.out.println("Key URL: " + key.getUrl());
} else {
KeyType type = key.getContentType();
if (type == null) {
//the vCard may not have any content type data associated with the key
System.out.println("Saving a key file...");
} else {
System.out.println("Saving a \"" + type.getMediaType() + "\" file...");
}
String folder;
if (type == KeyType.PGP){ //it is safe to use "==" instead of "equals()"
folder = "pgp-keys";
} else {
folder = "other-keys";
}
byte data[] = key.getData();
String filename = "key" + fileCount;
if (type != null && type.getExtension() != null){
filename += "." + type.getExtension();
}
OutputStream out = new FileOutputStream(new File(folder, filename));
out.write(data);
out.close();
fileCount++;
}
}
Property name: KEY
Supported versions: 2.1, 3.0, 4.0
| Field Summary |
|---|
| Fields inherited from class ezvcard.property.BinaryProperty |
|---|
contentType, data, url |
| Fields inherited from class ezvcard.property.VCardProperty |
|---|
group, parameters |
| Constructor Summary | |
|---|---|
Key()
Creates an empty key property. |
|
Key(byte[] data,
KeyType type)
Creates a key property. |
|
Key(File file,
KeyType type)
Creates a key property. |
|
Key(InputStream in,
KeyType type)
Creates a key property. |
|
Key(String url,
KeyType type)
Creates a key property. |
|
| Method Summary | |
|---|---|
protected void |
_validate(List<Warning> warnings,
VCardVersion version,
VCard vcard)
Checks the property for data consistency problems or deviations from the spec. |
String |
getText()
Gets the plain text representation of the key. |
void |
setText(String text,
KeyType type)
Sets a plain text representation of the key. |
| Methods inherited from class ezvcard.property.BinaryProperty |
|---|
addPid, getAltId, getContentType, getData, getPids, getPref, getType, getUrl, removePids, setAltId, setContentType, setData, setPref, setType, setUrl |
| Methods inherited from class ezvcard.property.VCardProperty |
|---|
_supportedVersions, addParameter, compareTo, getGroup, getParameter, getParameters, getParameters, getSupportedVersions, removeParameter, setGroup, setParameter, setParameters, validate |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public Key()
public Key(byte[] data,
KeyType type)
data - the binary datatype - the type of key (e.g. PGP)
public Key(String url,
KeyType type)
url - the URL to the key (vCard 4.0 only)type - the type of key (e.g. PGP)
public Key(InputStream in,
KeyType type)
throws IOException
in - an input stream to the binary data (will be closed)type - the content type (e.g. PGP)
IOException - if there's a problem reading from the input stream
public Key(File file,
KeyType type)
throws IOException
file - the key filetype - the content type (e.g. PGP)
IOException - if there's a problem reading from the file| Method Detail |
|---|
public void setText(String text,
KeyType type)
text - the key in plain texttype - the key typepublic String getText()
protected void _validate(List<Warning> warnings,
VCardVersion version,
VCard vcard)
VCardProperty
_validate in class BinaryProperty<KeyType>warnings - the list to add the warnings toversion - the version to check the property againstvcard - the vCard this property belongs to
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||