|
freiheit.com technologies gmbh | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.freiheit.gnupg.GnuPGPeer
com.freiheit.gnupg.GnuPGContext
public class GnuPGContext
Start here, because for all operations, you first need to create a GnuPGContext. Use one context object for every single thread or (really) take care about synchronizing access to the context from different threads.
How to create a context?
GnuPGContext ctx = new GnuPGContext();
If you execute an operation, where GnuPG needs a passphrase
(password, mantra) from you, you need to tell the
library which Class is listening for such a request and is able to
deliver the entered passphrase to the library. You can implement
such a listener by yourself, but you can also use two
pre-fabricated ones. (Of course, normally you should install
gpg-agent/pinentry for this job...but some will need this ability
to get passphrases from a database or so. And: This release is not
checking for the existence of gpg-agent...so it won't work anyway.)
How to add a Passphrase-Listener to read a password from the console?
ctx.setPassphraseListener(new GnuPGPassphraseConsole());
//caution: you can still see the password while you are typing...
How to add a Passphrase-Listener to read a password from the swing dialog?
ctx.setPassphraseListener(new GnuPGPassphraseWindow());
| Constructor Summary | |
|---|---|
GnuPGContext()
Creates a new Context (use on context for one thread!) |
|
| Method Summary | |
|---|---|
void |
addSigner(GnuPGKey key)
Adds a Signer to this context. |
void |
clearSigners()
Removes all signers from this context. |
GnuPGData |
createDataObject()
Factory method to generate an empty GnuPGData-Object. |
GnuPGData |
createDataObject(byte[] data)
Factory method to generate a GnuPGData-Object from a byte array. |
GnuPGData |
createDataObject(java.lang.String data)
Factory method to generate a GnuPGData-Object from a String. |
void |
decrypt(GnuPGData cipher,
GnuPGData plain)
Decrypts the data from cipher and stores the result in plain. |
void |
destroy()
This calls immediately the release method for the context in the underlying gpgme library. |
void |
encrypt(GnuPGKey[] recipients,
GnuPGData plain,
GnuPGData cipher)
Encrypts the data from plain with the public key of each recipient. |
protected void |
finalize()
Releases underlying datastructures. |
GnuPGKey[] |
generateEmptyKeyArray(int withLengthOf)
Convenience method to generate empty key arrays. |
java.lang.String |
getFilename()
Returns the executable gpg with path |
GnuPGKey |
getKeyByFingerprint(java.lang.String fingerprint)
Gets the key with the supplied fingerprint from the keyring. |
java.lang.String |
getRequiredVersion()
Returns the required version of the underlying GPGME lib. |
java.lang.String |
getVersion()
Returns the version of the underlying GPGME lib version. |
boolean |
isArmor()
Tells you, is the gpg engine uses ASCII armor. |
boolean |
isTextmode()
Tells you, is the gpg engine is in text mode. |
GnuPGKey[] |
searchKeys(java.lang.String query)
Find all keys matching query in keyring. |
void |
setArmor(boolean state)
Tell the gpg engine to use ASCII armor. |
void |
setPassphraseListener(GnuPGPassphraseListener l)
Sets a listener, if GPGME needs to request a passphrase from the user (or even from a program or a database..) |
void |
setTextmode(boolean state)
Tell the gpg engine to set the text mode. |
void |
sign(GnuPGData plain,
GnuPGData signature)
Signs the data in plain and stores the result in signature. |
void |
verify(GnuPGData signature,
GnuPGData signed,
GnuPGData plain)
Verifies a signature. |
| Methods inherited from class com.freiheit.gnupg.GnuPGPeer |
|---|
getInternalRepresentation, setInternalRepresentation |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public GnuPGContext()
| Method Detail |
|---|
public java.lang.String getVersion()
public java.lang.String getFilename()
public java.lang.String getRequiredVersion()
public boolean isArmor()
public void setArmor(boolean state)
state - set true if results should be ASCII armored, set false if binarypublic boolean isTextmode()
public void setTextmode(boolean state)
state - set true if you want text mode switched onpublic void setPassphraseListener(GnuPGPassphraseListener l)
A passphrase-listener is global to a jvm. This means, you can register only one listener.
I am working on this, but it is not so easy to access jvm methods from a specific object from a non-jvm thread, which the passphrase callback is...
l - a GnuPGPassphraseListener implementationGnuPGPassphraseListener
public GnuPGKey getKeyByFingerprint(java.lang.String fingerprint)
throws GnuPGException
fingerprint - gpg fingerprint (must be in your keyring)
GnuPGExceptionGnuPGKey
public GnuPGData createDataObject(java.lang.String data)
throws GnuPGException
data - should not be null and should have a length > 0
GnuPGException
public GnuPGData createDataObject(byte[] data)
throws GnuPGException
data - should not be null and should have a length > 0
GnuPGException
public GnuPGData createDataObject()
throws GnuPGException
data - should not be null and should have a length > 0
GnuPGExceptionpublic GnuPGKey[] generateEmptyKeyArray(int withLengthOf)
withLengthOf - length of the array to generate (number of recipients)
GnuPGKey
public GnuPGKey[] searchKeys(java.lang.String query)
throws GnuPGException
query - allows the same expressions as gpg on command line
GnuPGExceptionGnuPGKey
public void encrypt(GnuPGKey[] recipients,
GnuPGData plain,
GnuPGData cipher)
throws GnuPGException
recipients - Array with the public keys of all recipientsplain - text, that should be encryptedcipher - text, the encrypted plain text after method call
GnuPGExceptionGnuPGData,
GnuPGKey
public void decrypt(GnuPGData cipher,
GnuPGData plain)
throws GnuPGException
cipher - text, holds the cipher to be decryptedplain - text, holds the decrypted text after decryption
GnuPGExceptionGnuPGData
public void sign(GnuPGData plain,
GnuPGData signature)
throws GnuPGException
plain - data that you want to signsignature - result of the operation
GnuPGException
public void verify(GnuPGData signature,
GnuPGData signed,
GnuPGData plain)
throws GnuPGException
signature - TODOsigned - TODOplain - TODO
GnuPGException
public void addSigner(GnuPGKey key)
throws GnuPGException
key - that should be used for signing operations
GnuPGExceptionGnuPGKey
public void clearSigners()
throws GnuPGException
GnuPGExceptionpublic void destroy()
protected void finalize()
finalize in class java.lang.Object
|
freiheit.com technologies gmbh | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||