com.didisoft.pgp
Class KeyPairInformation

java.lang.Object
  extended by com.didisoft.pgp.KeyPairInformation
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
PGPKeyPair

public class KeyPairInformation
extends java.lang.Object
implements java.io.Serializable

Represents an OpenPGP key pair.

See Also:
Serialized Form

Nested Class Summary
 class KeyPairInformation.SubKey
          Represents a sub key in a key ring
 
Method Summary
 boolean checkPassword(java.lang.String password)
          Checks if a password for a private key is correct
 void exportKeyRing(java.lang.String fileName, boolean asciiArmored)
          Exports the key pair (both the public and the private key if available) located in this object in one file.
 void exportPrivateKey(java.lang.String fileName, boolean asciiArmored)
          Exports the private key part of this key pair into a file.
 void exportPublicKey(java.lang.String fileName, boolean asciiArmored)
          Exports the public key part of this key pair into a file.
 java.lang.String getAlgorithm()
          Returns the name of the key encryption asymmetric algorithm.
 java.util.Date getCreationTime()
          Returns when was the key created.
 int getEncryptionKeySize()
          The bit strength of the encryption sub key
 java.util.Date getExpirationDate()
          Returns the date when this key will expire
 java.util.Date getExpirationTime()
          Returns the key expiration date
 java.lang.String getFingerprint()
          Returns the key fingerprint as string.
 long getKeyID()
          Returns the Key ID of this key pair.
 java.lang.String getKeyIDHex()
          Returns a string representing the hexadecimal value of the Key ID.
 java.lang.String getKeyIDLongHex()
          Returns a string representing the hexadecimal value of the Key ID.
 int getKeySize()
          Returns key size in bits.
 int[] getPreferredCiphers()
          The preferred cipher algorithms supported by this key.
 int[] getPreferredCompressions()
          The preferred compression algorithms supported by this key.
 int[] getPreferredHashes()
          The preferred hash algorithms supported by this key.
 KeyPairInformation.SubKey[] getPrivateSubKeys()
          Returns an array from all private sub keys.
 KeyPairInformation.SubKey[] getPublicSubKeys()
          Returns an array from all public sub keys.
 lw.bouncycastle.openpgp.PGPSecretKeyRing getRawPrivateKeyRing()
          Returns the Private key ring part of this Key Pair.
 lw.bouncycastle.openpgp.PGPPublicKeyRing getRawPublicKeyRing()
          Returns the Public key ring part of this Key Pair
 long[] getSignedWithKeyIds()
          Returns a list of the key Id's that have signed the public key(s) included in this key pair
 byte getTrust()
          Returns the trust data assigned to this key
 java.lang.String getUserID()
          Returns the primary (first) User Id associated with this key.
 java.lang.String[] getUserIDs()
          Returns User Id's associated with this key.
 int getValidDays()
          Returns key validity period in days.
 int getVersion()
          Returns key format OpenPGP version.
 boolean hasPrivateKey()
          Returns is there a private key in this key pair.
 boolean isEncryptionKey()
          Returns true if this key can be used for encryption, otherwise false
 boolean isExpired()
          Returns is this key expired (not usable any more).
 boolean isExpiredOnDate(java.util.Date date)
          Returns will this key be expired on a given date
 boolean isRevoked()
          Returns is this Key revoked (not usable any more).
 boolean isSigningKey()
          Returns is this Key used for signing data.
 boolean isValidForever()
          Returns does this key have an expiration date, or is valid forever
static java.lang.String keyId2Hex(long keyId)
          Helper method that converts 8 byte key id (of type long) into a hexadecimal string obtained from the lower 4 bytes.
static java.lang.String keyIdToHex(long keyId)
          Helper method that converts 8 byte key id (of type long) into a hexadecimal string obtained from the lower 4 bytes.
static java.lang.String keyIdToLongHex(long keyId)
          Helper method that converts a key id (of type long) into a hexadecimal string.
 void setPrivateKeyRing(lw.bouncycastle.openpgp.PGPSecretKeyRing secRing)
          Sets the Private key ring part of this Key Pair.
 void setPublicKeyRing(lw.bouncycastle.openpgp.PGPPublicKeyRing pubRing)
          Sets the Public key ring part of this Key Pair.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

setPublicKeyRing

public void setPublicKeyRing(lw.bouncycastle.openpgp.PGPPublicKeyRing pubRing)
Sets the Public key ring part of this Key Pair. (Used by KeyStore.getKeys())


setPrivateKeyRing

public void setPrivateKeyRing(lw.bouncycastle.openpgp.PGPSecretKeyRing secRing)
Sets the Private key ring part of this Key Pair. (Used by KeyStore.getKeys())


getPublicSubKeys

public KeyPairInformation.SubKey[] getPublicSubKeys()
Returns an array from all public sub keys.

Returns:
public sub keys

getPrivateSubKeys

public KeyPairInformation.SubKey[] getPrivateSubKeys()
Returns an array from all private sub keys.

Returns:
private sub keys

isExpired

public boolean isExpired()
Returns is this key expired (not usable any more).

Returns:
true if the key is expired, false if not

isExpiredOnDate

public boolean isExpiredOnDate(java.util.Date date)
Returns will this key be expired on a given date

Returns:
true if the key is expired on that date, false if not

isValidForever

public boolean isValidForever()
Returns does this key have an expiration date, or is valid forever

Returns:
true if valid forever, false if will expire

getExpirationDate

public java.util.Date getExpirationDate()
Returns the date when this key will expire

Returns:
date when this key will expire
See Also:
#isValidForever()}

isRevoked

public boolean isRevoked()
Returns is this Key revoked (not usable any more).


isEncryptionKey

public boolean isEncryptionKey()
Returns true if this key can be used for encryption, otherwise false


isSigningKey

public boolean isSigningKey()
Returns is this Key used for signing data.


getRawPublicKeyRing

public lw.bouncycastle.openpgp.PGPPublicKeyRing getRawPublicKeyRing()
Returns the Public key ring part of this Key Pair


getRawPrivateKeyRing

public lw.bouncycastle.openpgp.PGPSecretKeyRing getRawPrivateKeyRing()
Returns the Private key ring part of this Key Pair.
May be null if only public key is available.


hasPrivateKey

public boolean hasPrivateKey()
Returns is there a private key in this key pair.

Returns:
true if there is a private key in this key pair, otherwise false

keyId2Hex

public static java.lang.String keyId2Hex(long keyId)
Helper method that converts 8 byte key id (of type long) into a hexadecimal string obtained from the lower 4 bytes.
This hexadecimal key id string is the same as the one displayed by PGP(r) and GnuPG/gpg.

Parameters:
keyId - Key ID of type long
Returns:
hexadecimal Key ID

keyIdToHex

public static java.lang.String keyIdToHex(long keyId)
Helper method that converts 8 byte key id (of type long) into a hexadecimal string obtained from the lower 4 bytes.
This hexadecimal key id string is the same as the one displayed by PGP(r) and GnuPG/gpg.

Parameters:
keyId - Key ID of type long
Returns:
hexadecimal Key ID

keyIdToLongHex

public static java.lang.String keyIdToLongHex(long keyId)
Helper method that converts a key id (of type long) into a hexadecimal string.
This hexadecimal key id string is the same as the one displayed by PGP(r) and GnuPG/gpg.

Parameters:
keyId - Key ID of type long
Returns:
hexadecimal Key ID

getKeyID

public long getKeyID()
Returns the Key ID of this key pair.


getKeyIDHex

public java.lang.String getKeyIDHex()
Returns a string representing the hexadecimal value of the Key ID.

Changed to return Headecimal string for only the lower 4 bytes, being that way the same as the one displayed by PGP (r) and GnuPG.

Since:
2.5.2

getKeyIDLongHex

public java.lang.String getKeyIDLongHex()
Returns a string representing the hexadecimal value of the Key ID.

Since:
3.1.2

getFingerprint

public java.lang.String getFingerprint()
Returns the key fingerprint as string.


getUserID

public java.lang.String getUserID()
Returns the primary (first) User Id associated with this key.

Returns:
first user Id or null if none exists

getUserIDs

public java.lang.String[] getUserIDs()
Returns User Id's associated with this key.

Returns:
array of user Id's

getKeySize

public int getKeySize()
Returns key size in bits.

Returns:
key size in bits.

getAlgorithm

public java.lang.String getAlgorithm()
Returns the name of the key encryption asymmetric algorithm.


getCreationTime

public java.util.Date getCreationTime()
Returns when was the key created.


getValidDays

public int getValidDays()
Returns key validity period in days.


getExpirationTime

public java.util.Date getExpirationTime()
Returns the key expiration date

Returns:
key expiration date, if the key does not expire the returned date getTime() property is equal to Long.MAX_VALUE

getVersion

public int getVersion()
Returns key format OpenPGP version.


exportPublicKey

public void exportPublicKey(java.lang.String fileName,
                            boolean asciiArmored)
                     throws java.io.IOException
Exports the public key part of this key pair into a file.

Example:
 import com.didisoft.pgp.PGPKeyPair;
 
 public class ExportPublicKeyDemo {
     public static void main(String[] args) throws Exception{
         // initialize the key object
         PGPKeyPair key = new PGPKeyPair("my_key.pgp");
         
         // should the exported key be in ASCII form (true), or binary (false)
         boolean asciiArmored = true;
         
         // export the public key
         key.exportPublicKey("my_public_key.asc", asciiArmored);     
     }
 }
 

Parameters:
fileName - File name where the public key will be exported (absolute or relative path)
asciiArmored - if true, out is ASCII armored, if false binary file format is used.
Throws:
java.io.IOException - if an I/O error occurs.

exportPrivateKey

public void exportPrivateKey(java.lang.String fileName,
                             boolean asciiArmored)
                      throws NoPrivateKeyFoundException,
                             java.io.IOException
Exports the private key part of this key pair into a file.
If there is no private key available in the key pair object an exception of type NoPrivateKeyFoundException will be thrown

Example:
 import com.didisoft.pgp.PGPKeyPair;
 
 public class ExportPrivateKeyDemo {
     public static void main(String[] args) throws Exception{
         // initialize the key object
         PGPKeyPair key = new PGPKeyPair("my_key.pgp");
         
         // should the exported key be in ASCII form (true), or binary (false)
         boolean asciiArmored = true;
         
         // export the private key
         key.exportPrivateKey("my_private_key.asc", asciiArmored);     
     }
 }
 

Parameters:
fileName - File name where the public key will be exported (absolute or relative path)
asciiArmored - if true, out is ASCII armored, when false binary file format is used.
Throws:
NoPrivateKeyFoundException - if there is no private key loaded in this key pair object
java.io.IOException - if an I/O error occurs.

exportKeyRing

public void exportKeyRing(java.lang.String fileName,
                          boolean asciiArmored)
                   throws java.io.IOException
Exports the key pair (both the public and the private key if available) located in this object in one file.
The result file is in ASCII armored format. The private key is exported only if exists.

Example:
 import com.didisoft.pgp.PGPKeyPair;
 
 public class ExportKeyPairDemo {
     public static void main(String[] args) throws Exception{
         // initialize the key store
         PGPKeyPair key = new PGPKeyPair("my_key.pgp");
         
         // export the key pair
         keyStore.exportKeyRing("keypair.asc");     
     }
 }
 

Parameters:
fileName - File name where the key pair will be exported (absolute or relative path)
Throws:
java.io.IOException - I/O error saving the key ring

checkPassword

public boolean checkPassword(java.lang.String password)
                      throws NoPrivateKeyFoundException
Checks if a password for a private key is correct

Parameters:
password - to be checked
Returns:
true if the password for the private key in this key pair is correct, false otherwise
Throws:
NoPrivateKeyFoundException - If there is no private key in this key pair

getTrust

public byte getTrust()
Returns the trust data assigned to this key

Returns:
trust data level
See Also:
TrustLevel

getPreferredCompressions

public int[] getPreferredCompressions()
The preferred compression algorithms supported by this key.

Returns:
array of preferred compression algorithms
See Also:
CompressionAlgorithm

getPreferredCiphers

public int[] getPreferredCiphers()
The preferred cipher algorithms supported by this key.

Returns:
array of preferred cipher algorithms
See Also:
CypherAlgorithm

getPreferredHashes

public int[] getPreferredHashes()
The preferred hash algorithms supported by this key.

Returns:
array of preferred hash algorithms
See Also:
HashAlgorithm

getSignedWithKeyIds

public long[] getSignedWithKeyIds()
Returns a list of the key Id's that have signed the public key(s) included in this key pair

Returns:
list of the signing key Id's

getEncryptionKeySize

public int getEncryptionKeySize()
The bit strength of the encryption sub key

Returns:
bit strength of the encryption sub key
See Also:
getKeySize()


Copyright © 2006-2017 DidiSoft Ltd. All Rights Reserved.