|
||||||||||
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 |
generateEccKeyPair(java.lang.String ecCurve,
java.lang.String userId,
java.lang.String password)
Generates an OpenPGP key pair with Elliptic Curve cryptography (ECC) asymmetric encryption algorithm Note: The generated key pair has no expiration date |
static PGPKeyPair |
generateEccKeyPair(java.lang.String ecCurve,
java.lang.String userId,
java.lang.String password,
java.lang.String[] compressionTypes,
java.lang.String[] hashingAlgorithmTypes,
java.lang.String[] cipherTypes)
Generates an OpenPGP key pair with Elliptic Curve cryptography (ECC) asymmetric encryption algorithm Note: The generated key pair has no expiration date |
static PGPKeyPair |
generateEccKeyPair(java.lang.String ecCurve,
java.lang.String userId,
java.lang.String password,
java.lang.String[] compressionTypes,
java.lang.String[] hashingAlgorithmTypes,
java.lang.String[] cipherTypes,
long expirationAfterDays)
Generates an OpenPGP key pair with Elliptic Curve cryptography (ECC) asymmetric encryption algorithm |
static PGPKeyPair |
generateElGamalKeyPair(int keySize,
java.lang.String userId,
java.lang.String password)
Generates OpenPGP Key pair with ElGamal (DH/DSS) encryption and predefined values for compression, hashing and cypher like the ones generated with PGP Desktop(tm) key generation wizard. |
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). |
static PGPKeyPair |
generateRsaKeyPair(int keySize,
java.lang.String userId,
java.lang.String password)
Generates OpenPGP Key pair with RSA encryption and predefined values for compression, hashing and cypher like the ones generated with PGP Desktop(tm) key generation wizard. |
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, getUserID, getUserIDs, getValidDays, getVersion, hasPrivateKey, isEncryptionKey, isExpired, isExpiredOnDate, isRevoked, isSigningKey, keyId2Hex, 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 pairpublic 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 publicKeyFileNameMethod 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: fieldpublic static PGPKeyPair generateEccKeyPair(java.lang.String ecCurve, java.lang.String userId, java.lang.String password) throws PGPException
ecCurve
- Elliptic curve of the key pair (see EcCurve
for supported curves)userId
- user Id of this keypassword
- password for the private key (can be empty string if none)
PGPKeyPair
object representing the newly created key pair
PGPException
- if an error occurs
java.lang.IllegalArgumentException
- if the curve parameter or one of the preferred algorithms parameters is invalid
import com.didisoft.pgp.*; public class GenerateECCKeyPair { public static void main(String[] args) throws Exception { // key primary user Id String userId = "demo2@didisoft.com"; String privateKeyPassword = "changeit"; // EC curve for this key String curve = EcCurve.P384; PGPKeyPair key = PGPKeyPair.generateEccKeyPair(curve, userId, privateKeyPassword); // we can call key.export ... in order to save the generated key in a file } }
public static PGPKeyPair generateEccKeyPair(java.lang.String ecCurve, java.lang.String userId, java.lang.String password, java.lang.String[] compressionTypes, java.lang.String[] hashingAlgorithmTypes, java.lang.String[] cipherTypes) throws PGPException
ecCurve
- Elliptic curve of the key pair (see EcCurve
for supported curves)userId
- user Id of this keypassword
- password for the private key (can be empty string if none)compressionTypes
- Compression algorithms supported by the key. (see CompressionAlgorithm
)hashingAlgorithmTypes
- Hashing algorithms supported by the key. (see HashAlgorithm
)cipherTypes
- Symmetric algorithms supported by the key. (see CypherAlgorithm
)
PGPKeyPair
object representing the newly created key pair
PGPException
- if an error occurs
java.lang.IllegalArgumentException
- if the curve parameter or one of the preferred algorithms parameters is invalid
import com.didisoft.pgp.*; public class GenerateECCKeyPair { 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.SHA256, HashAlgorithm.SHA384, HashAlgorithm.SHA512}; // preferred compression algorithms String[] compressions = new String[] {CompressionAlgorithm.ZIP, CompressionAlgorithm.ZLIB, CompressionAlgorithm.UNCOMPRESSED}; // preferred symmetric key algorithms String[] cyphers = new String[] {CypherAlgorithm.AES_128, CypherAlgorithm.AES_192, CypherAlgorithm.AES_256}; String privateKeyPassword = "changeit"; // EC curve for this key String curve = EcCurve.P384; PGPKeyPair key = PGPKeyPair.generateEccKeyPair(curve, userId, privateKeyPassword, compressions, hashingAlgorithms, cyphers, keyExpiresAfter); // we can call key.export ... in order to save the generated key in a file } }
public static PGPKeyPair generateEccKeyPair(java.lang.String ecCurve, java.lang.String userId, java.lang.String password, java.lang.String[] compressionTypes, java.lang.String[] hashingAlgorithmTypes, java.lang.String[] cipherTypes, long expirationAfterDays) throws PGPException
ecCurve
- Elliptic curve of the key pair (see EcCurve
for supported curves)userId
- user Id of this keypassword
- password for the private key (can be empty string if none)compressionTypes
- Compression algorithms supported by the key. (see CompressionAlgorithm
)hashingAlgorithmTypes
- Hashing algorithms supported by the key. (see HashAlgorithm
)cipherTypes
- Symmetric algorithms supported by the key. (see CypherAlgorithm
)expirationAfterDays
- the key validity period in days
PGPKeyPair
object representing the newly created key pair
PGPException
- if an error occurs
java.lang.IllegalArgumentException
- if the curve parameter or one of the preferred algorithms parameters is invalid
import com.didisoft.pgp.*; public class GenerateECCKeyPair { 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.SHA256, HashAlgorithm.SHA384, HashAlgorithm.SHA512}; // preferred compression algorithms String[] compressions = new String[] {CompressionAlgorithm.ZIP, CompressionAlgorithm.ZLIB, CompressionAlgorithm.UNCOMPRESSED}; // preferred symmetric key algorithms String[] cyphers = new String[] {CypherAlgorithm.AES_128, CypherAlgorithm.AES_192, CypherAlgorithm.AES_256}; String privateKeyPassword = "changeit"; // the key will be valid for 1 year long keyExpiresAfter = 365; // EC curve for this key String curve = EcCurve.P384; PGPKeyPair key = PGPKeyPair.generateEccKeyPair(curve, userId, privateKeyPassword, compressions, hashingAlgorithms, cyphers, keyExpiresAfter); // we can call key.export ... in order to save the generated key in a file } }
public static PGPKeyPair generateRsaKeyPair(int keySize, java.lang.String userId, java.lang.String password) 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"; String privateKeyPassword = "changeit"; int keySizeInBits = 2048; PGPKeyPair key = PGPKeyPair.generateRsaKeyPair(keySizeInBits, userId, privateKeyPassword); // 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>"password
- Secret key password.
org.bouncycastle.openpgp.PGPException
- Key generation error
PGPException
public static PGPKeyPair generateElGamalKeyPair(int keySize, java.lang.String userId, java.lang.String password) 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"; String privateKeyPassword = "changeit"; int keySizeInBits = 2048; PGPKeyPair key = PGPKeyPair.generateElGamalKeyPair(keySizeInBits, userId, privateKeyPassword); // 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>"password
- Secret key password.
org.bouncycastle.openpgp.PGPException
- Key generation error
PGPException
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)
com.didisoft.PGPException
- general error
PGPException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |