public class Key extends BinaryProperty<KeyType>
Defines a public encryption key.
Code sample (creating)
VCard vcard = new VCard(); //URL Key key = new Key("http://www.mywebsite.com/my-public-key.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);
Code sample (retrieving)
VCard vcard = ... for (Key key : vcard.getKeys()){ KeyType contentType = key.getContentType(); //e.g. "application/pgp-keys" String url = key.getUrl(); if (url != null){ //property value is a URL continue; } byte[] data = key.getData(); if (data != null){ //property value is binary data continue; } String text = key.getText(); if (text != null){ //property value is plain-text continue; } }
Property name: KEY
Supported versions: 2.1, 3.0, 4.0
contentType, data, url
group, parameters
Constructor and Description |
---|
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.
|
Modifier and Type | Method and Description |
---|---|
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.
|
addPid, getAltId, getContentType, getData, getPids, getPref, getType, getUrl, removePids, setAltId, setContentType, setData, setPref, setType, setUrl
_supportedVersions, addParameter, compareTo, getGroup, getParameter, getParameters, getParameters, getSupportedVersions, removeParameter, setGroup, setParameter, setParameters, validate
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 streampublic 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 filepublic 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 toThis software is published under the BSD license. Copyright © 2003-${build.year}, CRIXP AG, Switzerland, All rights reserved. Use is subject to license terms.