|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.didisoft.pgp.KeyStore
public class KeyStore
Represents an OpenPGP Key Store.
The KeyStore file contains both the public and secret key rings combined in one file and protected with password.
'
(In PGP (r) and GnuPG they are stored in two different files)
It can be used with PGPLib
in cases that require KeyStore
parameter,
or alone when only KeyStore or key generation operations are required.
Field Summary | |
---|---|
static java.lang.String |
DSA
DSA Algorithm constant, implementation of DH/DSS (signature) |
static java.lang.String |
ELGAMAL
ElGamal Algorithm constant, implementation of DH/DSS (encryption) |
static java.lang.String |
RSA
RSA Algorithm constant |
Constructor Summary | |
---|---|
KeyStore(java.lang.String keystoreFileName,
java.lang.String keystorePassword)
Creates a new Key Store object. |
Method Summary | |
---|---|
void |
addCertification(long keyId,
long certKeyId,
java.lang.String certPassword,
java.lang.String userID)
Appends certification to a given OpenPGP key in the key store. |
void |
changePrivateKeyPassword(long keyId,
java.lang.String oldPassword,
java.lang.String newPassword)
Changes private key password. |
boolean |
changePrivateKeyPassword(java.lang.String userId,
java.lang.String oldPassword,
java.lang.String newPassword)
Changes private key password. |
boolean |
containsKey(long keyId)
Returns true if a public or private key with the specified Key Id exists in this KeyStore Example: |
boolean |
containsKey(java.lang.String userId)
Returns true if public or private key with the specified User ID exists in this KeyStore Example: |
boolean |
containsPrivateKey(long keyId)
Returns true if a private key with the specified Key Id exists in this KeyStore Example: |
boolean |
containsPrivateKey(java.lang.String userId)
Returns true if a private key with the specified User ID exists in this KeyStore Example: |
boolean |
containsPublicKey(long keyId)
Returns true if a public key with the specified Key Id exists in this KeyStore Example: |
boolean |
containsPublicKey(java.lang.String userId)
Returns true if a public key with the specified User ID exists in this KeyStore Example: |
void |
deleteKeyPair(long keyId)
Deletes public and private key pair from this key store that have the specified Key Id. |
boolean |
deleteKeyPair(java.lang.String userId)
Deletes the first public and private key pair from this key store that have the specified User Id. |
boolean |
deletePrivateKey(long keyId)
Deletes the first private key with the specified User Id from this KeyStore. |
boolean |
deletePrivateKey(java.lang.String userId)
Deletes the first private key with the specified User Id from this KeyStore. |
boolean |
deletePublicKey(long keyId)
Deletes the first public key with the specified Key Id from this KeyStore. |
boolean |
deletePublicKey(java.lang.String userId)
Deletes the first public key with the specified User Id from this KeyStore. |
void |
exportKeyRing(java.lang.String fileName,
java.lang.String userId)
Exports Key ring (both public and private key) located in this Key store in one file. |
void |
exportPrivateKey(java.lang.String fileName,
long keyId,
boolean asciiArmored)
Exports private key from this KeyStore instance, into a file. |
void |
exportPrivateKey(java.lang.String fileName,
java.lang.String userId,
boolean asciiArmored)
Exports private key from this OpenPGP key store, into a file. |
void |
exportPublicKey(java.lang.String fileName,
long keyId,
boolean asciiArmored)
Exports public key from this KeyStore instance into a file. |
void |
exportPublicKey(java.lang.String fileName,
java.lang.String userId,
boolean asciiArmored)
Exports public key from this KeyStore instance into a file. |
void |
generateKeyPair(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. |
void |
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)
Generates OpenPGP key pair (public and private key). |
void |
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)
Generates OpenPGP Key pair (public and private key). |
void |
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 OpenPGP Key pair (public and private key). |
java.lang.String[] |
getKeyHexIds()
Returns array of Hexadecimal string representation of the key Id's for the keys contained in this KeyStore instance. |
long |
getKeyIdForKeyIdHex(java.lang.String keyIdHex)
Returns the real Key ID (of type long ) corresponding to this Hexadecimal Key Id. |
long |
getKeyIdForUserId(java.lang.String userId)
Returns the real Key ID (of type long ) corresponding to this User Id. |
KeyPairInformation[] |
getKeys()
Returns the key pairs stored in this OpenPGP key store. |
java.lang.String[] |
getUserIds()
Returns array of Strings representing all user Id's contained in this KeyStore instance. |
void |
importKeyRing(java.lang.String keyRingFileName)
Imports OpenPGP key ring into this KeyStore instance. |
void |
importPrivateKey(java.lang.String privateKeyFileName)
Imports a private key file into this KeyStore instance. |
void |
importPrivateKey(java.lang.String privateKeyFileName,
java.lang.String password)
Imports private key file into this KeyStore instance. |
void |
importPublicKey(java.lang.String publicKeyFileName)
Imports Public key into this KeyStore instance. |
void |
importPublickKey(java.lang.String publicKeyFileName)
Deprecated. Replaced by importPublicKey(String) |
boolean |
isAutoSave()
Returns is auto save on. |
boolean |
isBackupOnSave()
Returns should backups be made on save. |
void |
listKeys()
Lists keys stored in this OpenPGP key store to Stestem.out like PGP (r) 6.5
Example: |
void |
save()
Saves the backing file of this KeyStore instance to disk. |
void |
setAutoSave(boolean save)
Sets the KeyStore to call save() automatically after each
operation that modifies it (for example import key, delete key, etc.) |
void |
setBackupOnSave(boolean backupOnSave)
Sets backup file be created (with extension .bak) for this KeyStore on save() operations. |
void |
signPublicKey(long keyId,
long signKeyId,
java.lang.String signPassword)
Signs a public key with a private key. |
void |
signPublicKey(java.lang.String keyUserId,
java.lang.String signKeyUserId,
java.lang.String signPassword)
Signs a public key with a private key. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String ELGAMAL
public static final java.lang.String DSA
public static final java.lang.String RSA
Constructor Detail |
---|
public KeyStore(java.lang.String keystoreFileName, java.lang.String keystorePassword) throws java.io.IOException, PGPException
keystoreFileName
- File name of the Key store (absolute or relative path)keystorePassword
- Password for the Key store.
java.io.IOException
- if an I/O error occurs
org.bouncycastle.openpgp.PGPException
- if PGP object different from public or private key ring is found in this file
PGPException
Method Detail |
---|
public java.lang.String[] getUserIds()
KeyStore
instance.
KeyStore
instancepublic java.lang.String[] getKeyHexIds()
KeyStore
instance.
KeyStore
instancepublic long getKeyIdForUserId(java.lang.String userId)
long
) corresponding to this User Id.
userId
- User Id of the key owner.
long
) corresponding to this User Id.
If there is no key with such User Id -1
is returned.public long getKeyIdForKeyIdHex(java.lang.String keyIdHex)
long
) corresponding to this Hexadecimal Key Id.
long
for given hex key.
import com.didisoft.pgp.KeyStore;
public class KeyIdHexDemo {
public static void main(String[] args) throws Exception{
// initialize a KeyStore instance
KeyStore keyStore = new KeyStore("pgp.keystore", "changeit");
// get the key id corresponding to this hexadecimal key id
String hexKeyId = "74BB3286";
long keyId = keyStore.getKeyIdForKeyIdHex(hexKeyId);
if (keyId == -1) {
System.out.println("No key found with Key Id " + hexKeyId);
return;
}
// ... Now we can use keyId in the PGPLib
methods
// that accept KeyStore object and key id.
}
}
keyIdHex
- Hexadecimal Key Id used by other OpenPG software (e.g. PGP (r) and GnuPG).
long
) corresponding to this Hexadecimal Key Id.
If there is no key with such Hexadecimal Key Id -1
is returned.public void addCertification(long keyId, long certKeyId, java.lang.String certPassword, java.lang.String userID) throws PGPException
keyId
- Key ID of the key to receive this certificationcertKeyId
- certifying key IDcertPassword
- certifying key passworduserID
- user id giving the certification
NoPublicKeyFoundException
- No public key has been found with such Key Id
NoPrivateKeyFoundException
- No private key has been found with such Key Id
org.bouncycastle.openpgp.PGPException
- OpenPGP signing error
PGPException
public void signPublicKey(long keyId, long signKeyId, java.lang.String signPassword) throws PGPException
KeyStore
and are sure that the trusted third party is really the person they claim to be, you can sign his/her keys.
Signing a key certifies that you know the owner of the keys.
import com.didisoft.pgp.*; public class SignKeyDemo { public static void main(String[] a) throws Exception { KeyStore keyStore = new KeyStore("mykeys.keystore", "password"); long partnerKeyId = keyStore.getKeyIdForKeyIdHex("2EDE06AC"); long mySecretKeyId = keyStore.getKeyIdForKeyIdHex("2EDE06AC"); keyStore.signPublicKey(partnerKeyId, mySecretKeyId, "my secret key password"); } }
keyId
- Key ID of the public key to be signedsignKeyId
- Key ID of the private key to sign the public key withsignPassword
- Password of the own private key
NoPublicKeyFoundException
- No public key has been found with such Key Id
NoPrivateKeyFoundException
- No private key has been found with such Key Id
org.bouncycastle.openpgp.PGPException
- OpenPGP signing error
PGPException
public void signPublicKey(java.lang.String keyUserId, java.lang.String signKeyUserId, java.lang.String signPassword) throws PGPException
KeyStore
and are sure that trusted third party is really the person they claim, you can sign his/her keys.
Signing a key certifies that you know the owner of the keys.
import com.didisoft.pgp.*; public class SignKeyDemo { public static void main(String[] a) throws Exception { KeyStore keyStore = new KeyStore("mykeys.keystore", "password"); String partnerUserId = "Partner Company ACM"; long mySecretKeyUserId = "My Company my@company.com"; keyStore.signPublicKey(partnerUserId, mySecretKeyUserId, "my secret key password"); } }
keyUserId
- User Id of the public key to be signedsignKeyUserId
- User Id of the private key to sign the public key withsignPassword
- Password of the own private key
org.bouncycastle.openpgp.PGPException
PGPException
public boolean deleteKeyPair(java.lang.String userId) throws PGPException
import com.didisoft.pgp.KeyStore; public class DeleteKeyPair { public static void main(String[] args) throws Exception{ // initialize the KeyStore instance KeyStore ks = new KeyStore("pgp.keystore", "changeit"); // delete the key pair with this User Id ks.deleteKeyPair("test@gmail.com"); } }
userId
- User Id of the form "name (comment) <email address>"
PGPException
public boolean deletePrivateKey(java.lang.String userId) throws PGPException
import com.didisoft.pgp.KeyStore; public class DeletePrivateKeyDemo { public static void main(String[] args) throws Exception{ // initialize the KeyStore instance KeyStore ks = new KeyStore("pgp.keystore", "changeit"); // delete the private key with this User Id ks.deletePrivateKey("test@gmail.com"); } }
userId
- User Id of the form "name (comment) <email address>"
PGPException
public boolean deletePrivateKey(long keyId) throws PGPException
import com.didisoft.pgp.KeyStore; public class DeletePrivateKeyDemo { public static void main(String[] args) throws Exception{ // initialize the KeyStore instance KeyStore ks = new KeyStore("pgp.keystore", "changeit"); // delete the private key with this Key Id long privateKeyId = ks.getKeyIdForKeyIdHex("2EDE06AC"); ks.deletePrivateKey(privateKeyId); } }
keyId
- Key Id of the private key to be deleted
PGPException
public boolean deletePublicKey(java.lang.String userId) throws PGPException
import com.didisoft.pgp.KeyStore; public class DeletePublicKeyDemo { public static void main(String[] args) throws Exception{ // initialize the KeyStore instance KeyStore ks = new KeyStore("pgp.keystore", "changeit"); // delete the public key with this User Id ks.deletePublicKey("test@gmail.com"); } }
userId
- User Id of the form "name (comment) <email address>"
PGPException
public boolean deletePublicKey(long keyId) throws PGPException
import com.didisoft.pgp.KeyStore; public class DeletePublicKeyDemo { public static void main(String[] args) throws Exception{ // initialize the KeyStore instance KeyStore ks = new KeyStore("pgp.keystore", "changeit"); // delete the public key with this Key Id long privateKeyId = ks.getKeyIdForKeyIdHex("2EDE06AC"); ks.deletePublicKey(privateKeyId); } }
keyId
- Key Id of the public key to be deleted
PGPException
public void deleteKeyPair(long keyId) throws PGPException
import com.didisoft.pgp.KeyStore; public class DeleteKeyPairDemo { public static void main(String[] args) throws Exception{ // initialize the KeyStore instance KeyStore ks = new KeyStore("pgp.keystore", "changeit"); // delete the key pair with this Key Id long keyId = ks.getKeyIdForKeyIdHex("2EDE06AC"); ks.deleteKeyPair(keyId); } }
keyId
- Key ID of the key pair
PGPException
public boolean changePrivateKeyPassword(java.lang.String userId, java.lang.String oldPassword, java.lang.String newPassword) throws WrongPasswordException, PGPException
import com.didisoft.pgp.KeyStore; public class ChangePrivateKeyPasswordDemo { public static void main(String[] args) throws Exception{ // initialize the KeyStore instance KeyStore ks = new KeyStore("pgp.keystore", "changeit"); // change the key password ks.changePrivateKeyPassword("My Company", "old password", "new password"); } }
userId
- private key User Id of the form "name (comment) <email address>"oldPassword
- current password of the private keynewPassword
- new password of the private key
WrongPasswordException
- if the old password is incorrect
org.bouncycastle.openpgp.PGPException
- general error
PGPException
public void changePrivateKeyPassword(long keyId, java.lang.String oldPassword, java.lang.String newPassword) throws NoPrivateKeyFoundException, WrongPasswordException, PGPException
import com.didisoft.pgp.KeyStore; public class ChangePrivateKeyPasswordDemo { public static void main(String[] args) throws Exception{ // initialize the KeyStore instance KeyStore ks = new KeyStore("pgp.keystore", "changeit"); // change the key password long keyId = ks.getKeyIdForKeyIdHex("2EDE06AC"); ks.changePrivateKeyPassword(keyId, "old password", "new password"); } }
keyId
- Key Id of the private keyoldPassword
- current password of the private keynewPassword
- new password of the private key
NoPrivateKeyFoundException
- no private key with the specified Key Id has been found
WrongPasswordException
- if the old password is incorrect
org.bouncycastle.openpgp.PGPException
- general error
PGPException
getKeyIdForKeyIdHex(String)
public void generateKeyPair(int keySize, java.lang.String userId, java.lang.String password) throws PGPException
keySize
- Size of the keys
import com.didisoft.pgp.KeyStore; public class GenerateRSAKeyPairDemo { public static void main(String[] args) throws Exception{ // initialize the KeyStore instance KeyStore ks = new KeyStore("pgp.keystore", "changeit"); // change the key password int keySize = 2048; String userId = "My Company"; ks.generateKeyPair(keyId, userId, "key password"); // the public key can now be exported and sent to our partners } }
userId
- User Id of the form "name (comment) <email address>"password
- Secret key password
org.bouncycastle.openpgp.PGPException
- Key generation error
PGPException
public void 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) throws PGPException
import com.didisoft.pgp.*; public class GenerateKeyPairRSA { public static void main(String[] args) throws Exception { // initialize the KeyStore where the key will be generated KeyStore ks = new KeyStore("pgp.keystore", "changeit"); // 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"; int keySizeInBits = 2048; ks.generateKeyPair(keySizeInBits, userId, KeyAlgorithm.RSA, privateKeyPassword, compressions, hashingAlgorithms, cyphers); } }
keySize
- Size of the keys in bits
userId
- User Id of the form "name (comment) <email address>"keyAlgorithm
- Key algorithm. Possible values: ELGAMAL, RSApassword
- 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. org.bouncycastle.openpgp.PGPException
- Key generation error
CompressionAlgorithm
PGPException
public void 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) throws PGPException
keySize
- Size of the keys in bits
userId
- User Id of the form "name (comment) <email address>"keyAlgorithm
- Key algorithm. Possible values: ELGAMAL, RSApassword
- Secret key password.compressionTypes
- Compression algorithms supported by the key. hashingAlgorithmTypes
- Hashing algorithms supported by the key. cipherTypes
- Symmetric algorithms supported by the key. org.bouncycastle.openpgp.PGPException
- Key generation error
PGPException
public void 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 { // initialize the KeyStore where the key will be generated KeyStore ks = new KeyStore("pgp.keystore", "changeit"); // 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; ks.generateKeyPair(keySizeInBits, userId, KeyAlgorithm.RSA, privateKeyPassword, compressions, hashingAlgorithms, cyphers, keyExpiresAfter); } }
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. hashingAlgorithmTypes
- 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 exportKeyRing(java.lang.String fileName, java.lang.String userId) throws NoPublicKeyFoundException, java.io.IOException
import com.didisoft.pgp.KeyStore; public class ExportKeyPairDemo { public static void main(String[] args) throws Exception{ // initialize the key store KeyStore keyStore = new KeyStore("pgp.keystore", "changeit"); // export key pair with this User Id keyStore.exportKeyRing("keypair.asc", "demo@didisoft.com"); } }
fileName
- File name where the key ring will be exported (absolute or relative path)userId
- User Id of the form "name (comment) <email address>"
NoPublicKeyFoundException
- if there is no such key
java.io.IOException
- I/O error saving the key ringpublic void exportPublicKey(java.lang.String fileName, java.lang.String userId, boolean asciiArmored) throws PGPException, java.io.IOException
import com.didisoft.pgp.KeyStore; public class ExportPublicKeyDemo { public static void main(String[] args) throws Exception{ // initialize the key store KeyStore keyStore = new KeyStore("pgp.keystore", "changeit"); // should the exported key be in ASCII form (true), or binary (false) boolean asciiArmored = true; // export the public key with this User Id keyStore.exportPublicKey("public_key.asc", "demo@didisoft.com", asciiArmored); } }
fileName
- File name where the public key will be exported (absolute or relative path)userId
- User Id of the form "name (comment) <email address>"asciiArmored
- if true, out is ASCII armored, when false binary file format is used.
org.bouncycastle.openpgp.PGPException
- if there is no such key
java.io.IOException
- if an I/O error occurs.
PGPException
public void exportPublicKey(java.lang.String fileName, long keyId, boolean asciiArmored) throws NoPublicKeyFoundException, java.io.IOException
import com.didisoft.pgp.KeyStore; public class ExportPublicKeyDemo { public static void main(String[] args) throws Exception{ // initialize the key store KeyStore keyStore = new KeyStore("pgp.keystore", "changeit"); // should the exported key be in ASCII form (true), or binary (false) boolean asciiArmored = true; long keyId = keyStore.getKeyIdForKeyIdHex("2EDE06AC"); // export key pair with this User Id keyStore.exportPublicKey("public_key.asc", keyId, asciiArmored); } }
fileName
- File name where the public key will be exported (absolute or relative path)keyId
- Key Id of the Public KeyasciiArmored
- if true, out is ASCII armored
NoPublicKeyFoundException
- if there is no such key
java.io.IOException
- if an I/O error occurs.public void exportPrivateKey(java.lang.String fileName, java.lang.String userId, boolean asciiArmored) throws NoPrivateKeyFoundException, java.io.IOException
import com.didisoft.pgp.KeyStore; public class ExportPrivateKeyDemo { public static void main(String[] args) throws Exception{ // initialize the key store KeyStore keyStore = new KeyStore("pgp.keystore", "changeit"); // should the exported key be in ASCII form (true), or binary (false) boolean asciiArmored = true; // export key pair with this User Id keyStore.exportPrivateKey("private_key.asc", "demo@didisoft.com", asciiArmored); } }
fileName
- File name where the key will be exported (absolute or relative path)userId
- User Id of the form "name (comment) <email address>"asciiArmored
- if true, out is ASCII armored
NoPrivateKeyFoundException
- if there is no such key
java.io.IOException
- if an I/O error occurs.public void exportPrivateKey(java.lang.String fileName, long keyId, boolean asciiArmored) throws NoPrivateKeyFoundException, java.io.IOException
import com.didisoft.pgp.KeyStore; public class ExportPrivateKeyDemo { public static void main(String[] args) throws Exception{ // initialize the key store KeyStore keyStore = new KeyStore("pgp.keystore", "changeit"); // should the exported key be in ASCII form (true), or binary (false) boolean asciiArmored = true; long keyId = keyStore.getKeyIdForKeyIdHex("2EDE06AC"); // export key pair with this User Id keyStore.exportPrivateKey("private_key.asc", keyId, asciiArmored); } }
fileName
- File name where the key will be exported (absolute or relative path)keyId
- Key Id of the corresponding Public KeyasciiArmored
- if true, out is ASCII armored
NoPrivateKeyFoundException
- if there is no such key
java.io.IOException
- if an I/O error occurs.public void importPublickKey(java.lang.String publicKeyFileName) throws java.io.IOException, PGPException
importPublicKey(String)
publicKeyFileName
- FileName of the Public key to be imported (absolute or relative path)
java.io.IOException
- if an I/O error occurs (for example file not found)
org.bouncycastle.openpgp.PGPException
- if PGP object different from public or private key is found in this file
PGPException
importKeyRing(String)
,
exportKeyRing(String, String)
public void importPublicKey(java.lang.String publicKeyFileName) throws java.io.IOException, PGPException
import com.didisoft.pgp.KeyStore; public class ImportKeyDemo { public static void main(String[] args) throws Exception{ // initialize the key store KeyStore keyStore = new KeyStore("pgp.keystore", "changeit"); // import key keyStore.importPublicKey("public_key.asc"); } }
publicKeyFileName
- FileName of the Public key to be imported (absolute or relative path)
java.io.IOException
- if an I/O error occurs (for example file not found)
org.bouncycastle.openpgp.PGPException
- if PGP object different from public or private key is found in this file
PGPException
public void importKeyRing(java.lang.String keyRingFileName) throws java.io.IOException, PGPException
import com.didisoft.pgp.KeyStore; public class ImportKeyDemo { public static void main(String[] args) throws Exception{ // initialize the key store KeyStore keyStore = new KeyStore("pgp.keystore", "changeit"); // import key keyStore.importKeyRing("mykey.asc"); } }
keyRingFileName
- FileName of the key ring to be imported (absolute or relative path). Most common file name extensions are .asc, .pkr, .skr, .pgp, .pgpkey
java.io.IOException
- if an I/O error occurs (for example file not found)
org.bouncycastle.openpgp.PGPException
- if PGP object different from public or private key is found in this file
PGPException
exportKeyRing(String, String)
public void importPrivateKey(java.lang.String privateKeyFileName) throws java.io.IOException, PGPException
import com.didisoft.pgp.KeyStore; public class ImportKeyDemo { public static void main(String[] args) throws Exception{ // initialize the key store KeyStore keyStore = new KeyStore("pgp.keystore", "changeit"); // import key keyStore.importPrivateKey("mykey.asc"); } }
privateKeyFileName
- File of the Private key to be imported (absolute or relative path)
java.io.IOException
- if an I/O error occurs (for example file not found)
org.bouncycastle.openpgp.PGPException
- if PGP object different from public or private key is found in this file
PGPException
public void importPrivateKey(java.lang.String privateKeyFileName, java.lang.String password) throws java.io.IOException, PGPException
import com.didisoft.pgp.KeyStore; public class ImportKeyDemo { public static void main(String[] args) throws Exception{ // initialize the key store KeyStore keyStore = new KeyStore("pgp.keystore", "changeit"); // import key keyStore.importPrivateKey("mykey.asc", "key password"); } }
privateKeyFileName
- File of the Private key to be imported (absolute or relative path)password
- Password of the private key
java.io.IOException
- if an I/O error occurs (for example file not found)
org.bouncycastle.openpgp.PGPException
- if PGP object different from public or private key is found in this file
PGPException
public void listKeys()
Stestem.out
like PGP (r) 6.5
import com.didisoft.pgp.KeyStore; import com.didisoft.pgp.PGPLib; public class ListKeys { public static void main(String[] args) throws Exception{ KeyStore keyStore = new KeyStore("pgp.keystore", "changeit"); keyStore.listKeys(); } }
getKeys()
public KeyPairInformation[] getKeys()
public boolean containsPublicKey(java.lang.String userId)
import com.didisoft.pgp.KeyStore; public class ContainsPublicKeyDemo { public static void main(String[] args) throws Exception{ // initialize the key store KeyStore keyStore = new KeyStore("pgp.keystore", "changeit"); boolean keyExists = keyStore.containsPublicKey("demo@didisoft.com"); } }
userId
- User ID of the form "name (comment) <email address>"
getKeyIdForUserId(String)
public boolean containsPrivateKey(java.lang.String userId)
import com.didisoft.pgp.KeyStore; public class ContainsPrivateKeyDemo { public static void main(String[] args) throws Exception{ // initialize the key store KeyStore keyStore = new KeyStore("pgp.keystore", "changeit"); boolean keyExists = keyStore.containsPrivateKey("demo@didisoft.com"); } }
userId
- User ID of the form "name (comment) <email address>"
getKeyIdForUserId(String)
public boolean containsKey(java.lang.String userId)
import com.didisoft.pgp.KeyStore; public class ContainsKeyDemo { public static void main(String[] args) throws Exception{ // initialize the key store KeyStore keyStore = new KeyStore("pgp.keystore", "changeit"); boolean keyExists = keyStore.containsKey("demo@didisoft.com"); } }
userId
- User ID of the form "name (comment) <email address>"
getKeyIdForUserId(String)
public boolean containsKey(long keyId)
import com.didisoft.pgp.KeyStore; public class ContainsKeyDemo { public static void main(String[] args) throws Exception{ // initialize the key store KeyStore keyStore = new KeyStore("pgp.keystore", "changeit"); long keyId = keyStore.getKeyIdForKeyIdHex("2EDE06AC"); boolean keyExists = keyStore.containsKey(keyId); } }
keyId
- Key Id of type long
getKeyIdForKeyIdHex(String)
public boolean containsPrivateKey(long keyId)
import com.didisoft.pgp.KeyStore; public class ContainsPrivateKeyDemo { public static void main(String[] args) throws Exception{ // initialize the key store KeyStore keyStore = new KeyStore("pgp.keystore", "changeit"); long keyId = keyStore.getKeyIdForKeyIdHex("2EDE06AC"); boolean keyExists = keyStore.containsPrivateKey(keyId); } }
keyId
- Key Id of type long
getKeyIdForKeyIdHex(String)
public boolean containsPublicKey(long keyId)
import com.didisoft.pgp.KeyStore; public class ContainsKeyDemo { public static void main(String[] args) throws Exception{ // initialize the key store KeyStore keyStore = new KeyStore("pgp.keystore", "changeit"); long keyId = keyStore.getKeyIdForKeyIdHex("2EDE06AC"); boolean keyExists = keyStore.containsPublicKey(keyId); } }
keyId
- Key Id of type long
getKeyIdForKeyIdHex(String)
public void setAutoSave(boolean save)
KeyStore
to call save()
automatically after each
operation that modifies it (for example import key, delete key, etc.)
save
- if true
this KeyStore
instance calls automatically it's save()
method.save()
,
isAutoSave()
public boolean isAutoSave()
true
by default)
true
if auto save mode is on, otherwise false
setAutoSave(boolean)
,
save()
public boolean isBackupOnSave()
true
by default)
true
if backup file is created on save, otherwise false
setBackupOnSave(boolean)
,
save()
public void setBackupOnSave(boolean backupOnSave)
backupOnSave
- if true
a backup file (with extension .bak) is created on each call to the save()
method.isBackupOnSave()
,
save()
public void save() throws PGPException
KeyStore
instance to disk.
isAutoSave()
is true
there is no need to be called explicitly, because it is called implicitly by all
methods that change the state of this KeyStore
instance.
org.bouncycastle.openpgp.PGPException
- error saving the state of this key store. Use the method getUnderlyingException() to see the cause.
PGPException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |