|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.didisoft.pgp.KeyPairInformation
com.didisoft.pgp.PGPKeyPair
public class PGPKeyPair
Represents an OpenPGP key loaded from a key file.
Provides methods for key generation and key export.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class com.didisoft.pgp.KeyPairInformation |
|---|
KeyPairInformation.SubKey |
| Constructor Summary | |
|---|---|
PGPKeyPair(java.lang.String fileName)
Initializes the object from a PGP key file. |
|
PGPKeyPair(java.lang.String publicKeyFileName,
java.lang.String privateKeyFileName)
Initializes the object from a public and private PGP key files. |
|
| Method Summary | |
|---|---|
void |
changePrivateKeyPassword(java.lang.String oldPassword,
java.lang.String newPassword)
Changes the password of this private key. |
static PGPKeyPair |
generateKeyPair(int keySize,
java.lang.String userId,
java.lang.String keyAlgorithm,
java.lang.String password,
java.lang.String[] compressionTypes,
java.lang.String[] hashingAlgorithmTypes,
java.lang.String[] cipherTypes,
long expirationAfterDays)
Generates an OpenPGP key pair (public and private key). |
java.lang.String |
getAsciiVersionHeader()
Returns the Version comment text that is printed in ASCII armored output |
void |
setAsciiVersionHeader(java.lang.String creator)
Sets the Version comment text that is printed in ASCII armored output Example usage: |
| Methods inherited from class com.didisoft.pgp.KeyPairInformation |
|---|
checkPassword, exportKeyRing, exportPrivateKey, exportPublicKey, getAlgorithm, getCreationTime, getFingerprint, getKeyID, getKeyIDHex, getKeySize, getPrivateSubKeys, getPublicSubKeys, getRawPrivateKeyRing, getRawPublicKeyRing, getTrust, getUserIDs, getValidDays, getVersion, hasPrivateKey, isEncryptionKey, isExpired, isExpiredOnDate, isRevoked, isSigningKey, setPrivateKeyRing, setPublicKeyRing |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public PGPKeyPair(java.lang.String fileName)
throws NoPublicKeyFoundException
fileName - absolute or relative path to a PGP key file.
NoPublicKeyFoundException - if the file specified through fileName does not contain a PGP key or key pair
public PGPKeyPair(java.lang.String publicKeyFileName,
java.lang.String privateKeyFileName)
throws NoPublicKeyFoundException,
WrongPrivateKeyException
publicKeyFileName - absolute or relative path to the public PGP key file.privateKeyFileName - absolute or relative path to the private PGP key file.
NoPublicKeyFoundException - if the file specified through publicKeyFileNameName does not contain a PGP key
WrongPrivateKeyException - if the private key specified with privateKeyFileName does not belong
to the public key specified with publicKeyFileName| Method Detail |
|---|
public java.lang.String getAsciiVersionHeader()
public void setAsciiVersionHeader(java.lang.String creator)
PGPKeyPair key = new PGPKeyPair("my_key.asc");
key.setAsciiVersionHeader("My Application 1.1");
// Now in ASCII armored export will be printed "Version: My Application 1.1"
creator - Program name and version that will be written in ASCII armored output Version: field
public static PGPKeyPair generateKeyPair(int keySize,
java.lang.String userId,
java.lang.String keyAlgorithm,
java.lang.String password,
java.lang.String[] compressionTypes,
java.lang.String[] hashingAlgorithmTypes,
java.lang.String[] cipherTypes,
long expirationAfterDays)
throws PGPException
import com.didisoft.pgp.*;
public class GenerateKeyPairRSA {
public static void main(String[] args) throws Exception {
// key primary user Id
String userId = "demo2@didisoft.com";
// preferred hashing algorithms
String[] hashingAlgorithms = new String[]
{HashAlgorithm.SHA1,
HashAlgorithm.SHA256,
HashAlgorithm.SHA384,
HashAlgorithm.SHA512,
HashAlgorithm.MD5};
// preferred compression algorithms
String[] compressions = new String[]
{CompressionAlgorithm.ZIP,
CompressionAlgorithm.ZLIB,
CompressionAlgorithm.UNCOMPRESSED};
// preferred symmetric key algorithms
String[] cyphers = new String[]
{CypherAlgorithm.CAST5,
CypherAlgorithm.AES_128,
CypherAlgorithm.AES_192,
CypherAlgorithm.AES_256,
CypherAlgorithm.TWOFISH};
String privateKeyPassword = "changeit";
// the key will be valid for 1 year
long keyExpiresAfter = 365;
int keySizeInBits = 2048;
PGPKeyPair key = PGPKeyPair.generateKeyPair(keySizeInBits,
userId,
KeyAlgorithm.RSA,
privateKeyPassword,
compressions,
hashingAlgorithms,
cyphers,
keyExpiresAfter);
// we can call key.export ... in order to save the generated key in a file
}
}
keySize - Size of the keys in bits
userId - User Id of the form "name (comment) <email address>"keyAlgorithm - Key algorithm. Possible values: RSA, ELGAMAL (equivalent of DS/DHH)password - Secret key password.compressionTypes - Compression algorithms supported by the key. @see CompressionAlgorithmhashingAlgorithmTypes - Hashing algorithms supported by the key. cipherTypes - Symmetric algorithms supported by the key. expirationAfterDays - Number of days the key will be valid. For example 365 for one year. Use 0 (zero) for no expiration date.
org.bouncycastle.openpgp.PGPException - Key generation error
PGPException
public void changePrivateKeyPassword(java.lang.String oldPassword,
java.lang.String newPassword)
throws WrongPasswordException,
NoPrivateKeyFoundException,
PGPException
import com.didisoft.pgp.*;
import com.didisoft.pgp.exceptions;
public class ChangePrivateKeyPasswordDemo {
public static void main(String[] args) throws Exception{
// initialize the key object
PGPKeyPair key = new PGPKeyPair("my_private_key.asc");
// change the key password
try {
key.changePrivateKeyPassword("old password", "new password");
} catch (WrongPasswordException e) }
System.out.println("The old password is not correct.");
}
}
}
oldPassword - current password of the private keynewPassword - new password of the private key
WrongPasswordException - if the old password is incorrect (extends PGPException)
NoPrivateKeyFoundException - if no private key has been loaded in this key pair object (extends PGPException)
org.bouncycastle.openpgp.PGPException - general error
PGPException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||