org.bouncycastle.openpgp

Class PGPSecretKey


public class PGPSecretKey
extends java.lang.Object

general class to handle a PGP secret key object.

Constructor Summary

PGPSecretKey(int certificationLevel, int algorithm, PublicKey pubKey, PrivateKey privKey, Date time, String id, int encAlgorithm, char[] passPhrase, boolean useSHA1, PGPSignatureSubpacketVector hashedPcks, PGPSignatureSubpacketVector unhashedPcks, SecureRandom rand, String provider)
PGPSecretKey(int certificationLevel, int algorithm, PublicKey pubKey, PrivateKey privKey, Date time, String id, int encAlgorithm, char[] passPhrase, PGPSignatureSubpacketVector hashedPcks, PGPSignatureSubpacketVector unhashedPcks, SecureRandom rand, String provider)
PGPSecretKey(int certificationLevel, PGPKeyPair keyPair, String id, int encAlgorithm, char[] passPhrase, boolean useSHA1, PGPSignatureSubpacketVector hashedPcks, PGPSignatureSubpacketVector unhashedPcks, SecureRandom rand, String provider)
PGPSecretKey(int certificationLevel, PGPKeyPair keyPair, String id, int encAlgorithm, char[] passPhrase, PGPSignatureSubpacketVector hashedPcks, PGPSignatureSubpacketVector unhashedPcks, SecureRandom rand, String provider)

Method Summary

static PGPSecretKey
copyWithNewPassword(PGPSecretKey key, char[] oldPassPhrase, char[] newPassPhrase, int newEncAlgorithm, SecureRandom rand, String provider)
Return a copy of the passed in secret key, encrypted using a new password and the passed in algorithm.
void
encode(OutputStream outStream)
PGPPrivateKey
extractPrivateKey(char[] passPhrase, String provider)
Extract a PGPPrivate key from the SecretKey's encrypted contents.
byte[]
getEncoded()
int
getKeyEncryptionAlgorithm()
return the algorithm the key is encrypted with.
long
getKeyID()
Return the keyID of the public key associated with this key.
PGPPublicKey
getPublicKey()
Return the public key associated with this key.
Iterator
getUserAttributes()
Return any user attribute vectors associated with the key.
Iterator
getUserIDs()
Return any userIDs associated with the key.
boolean
isMasterKey()
Return true if this is a master key.
boolean
isSigningKey()
return true if this key is marked as suitable for signature generation.

Constructor Details

PGPSecretKey

public PGPSecretKey(int certificationLevel,
                    int algorithm,
                    PublicKey pubKey,
                    PrivateKey privKey,
                    Date time,
                    String id,
                    int encAlgorithm,
                    char[] passPhrase,
                    boolean useSHA1,
                    PGPSignatureSubpacketVector hashedPcks,
                    PGPSignatureSubpacketVector unhashedPcks,
                    SecureRandom rand,
                    String provider)
            throws PGPException,
                   NoSuchProviderException

PGPSecretKey

public PGPSecretKey(int certificationLevel,
                    int algorithm,
                    PublicKey pubKey,
                    PrivateKey privKey,
                    Date time,
                    String id,
                    int encAlgorithm,
                    char[] passPhrase,
                    PGPSignatureSubpacketVector hashedPcks,
                    PGPSignatureSubpacketVector unhashedPcks,
                    SecureRandom rand,
                    String provider)
            throws PGPException,
                   NoSuchProviderException

PGPSecretKey

public PGPSecretKey(int certificationLevel,
                    PGPKeyPair keyPair,
                    String id,
                    int encAlgorithm,
                    char[] passPhrase,
                    boolean useSHA1,
                    PGPSignatureSubpacketVector hashedPcks,
                    PGPSignatureSubpacketVector unhashedPcks,
                    SecureRandom rand,
                    String provider)
            throws PGPException,
                   NoSuchProviderException

PGPSecretKey

public PGPSecretKey(int certificationLevel,
                    PGPKeyPair keyPair,
                    String id,
                    int encAlgorithm,
                    char[] passPhrase,
                    PGPSignatureSubpacketVector hashedPcks,
                    PGPSignatureSubpacketVector unhashedPcks,
                    SecureRandom rand,
                    String provider)
            throws PGPException,
                   NoSuchProviderException

Method Details

copyWithNewPassword

public static PGPSecretKey copyWithNewPassword(PGPSecretKey key,
                                               char[] oldPassPhrase,
                                               char[] newPassPhrase,
                                               int newEncAlgorithm,
                                               SecureRandom rand,
                                               String provider)
            throws PGPException,
                   NoSuchProviderException
Return a copy of the passed in secret key, encrypted using a new password and the passed in algorithm.
Parameters:
key - the PGPSecretKey to be copied.
oldPassPhrase - the current password for key.
newPassPhrase - the new password for the key.
newEncAlgorithm - the algorithm to be used for the encryption.
rand - source of randomness.
provider - the provider to use

encode

public void encode(OutputStream outStream)
            throws IOException

extractPrivateKey

public PGPPrivateKey extractPrivateKey(char[] passPhrase,
                                       String provider)
            throws PGPException,
                   NoSuchProviderException
Extract a PGPPrivate key from the SecretKey's encrypted contents.
Parameters:
passPhrase -
provider -
Returns:
PGPPrivateKey
Throws:
PGPException -

getEncoded

public byte[] getEncoded()
            throws IOException

getKeyEncryptionAlgorithm

public int getKeyEncryptionAlgorithm()
return the algorithm the key is encrypted with.
Returns:
the algorithm used to encrypt the secret key.

getKeyID

public long getKeyID()
Return the keyID of the public key associated with this key.
Returns:
the keyID associated with this key.

getPublicKey

public PGPPublicKey getPublicKey()
Return the public key associated with this key.
Returns:
the public key for this key.

getUserAttributes

public Iterator getUserAttributes()
Return any user attribute vectors associated with the key.
Returns:
an iterator of Strings.

getUserIDs

public Iterator getUserIDs()
Return any userIDs associated with the key.
Returns:
an iterator of Strings.

isMasterKey

public boolean isMasterKey()
Return true if this is a master key.
Returns:
true if a master key.

isSigningKey

public boolean isSigningKey()
return true if this key is marked as suitable for signature generation.