Bouncy Castle Cryptography 1.46

org.bouncycastle.openpgp
Class PGPSecretKey

java.lang.Object
  extended by org.bouncycastle.openpgp.PGPSecretKey

public class PGPSecretKey
extends java.lang.Object

general class to handle a PGP secret key object.


Constructor Summary
PGPSecretKey(int certificationLevel, int algorithm, java.security.PublicKey pubKey, java.security.PrivateKey privKey, java.util.Date time, java.lang.String id, int encAlgorithm, char[] passPhrase, boolean useSHA1, PGPSignatureSubpacketVector hashedPcks, PGPSignatureSubpacketVector unhashedPcks, java.security.SecureRandom rand, java.lang.String provider)
           
PGPSecretKey(int certificationLevel, int algorithm, java.security.PublicKey pubKey, java.security.PrivateKey privKey, java.util.Date time, java.lang.String id, int encAlgorithm, char[] passPhrase, PGPSignatureSubpacketVector hashedPcks, PGPSignatureSubpacketVector unhashedPcks, java.security.SecureRandom rand, java.lang.String provider)
           
PGPSecretKey(int certificationLevel, PGPKeyPair keyPair, java.lang.String id, int encAlgorithm, char[] passPhrase, boolean useSHA1, PGPSignatureSubpacketVector hashedPcks, PGPSignatureSubpacketVector unhashedPcks, java.security.SecureRandom rand, java.security.Provider provider)
           
PGPSecretKey(int certificationLevel, PGPKeyPair keyPair, java.lang.String id, int encAlgorithm, char[] passPhrase, boolean useSHA1, PGPSignatureSubpacketVector hashedPcks, PGPSignatureSubpacketVector unhashedPcks, java.security.SecureRandom rand, java.lang.String provider)
           
PGPSecretKey(int certificationLevel, PGPKeyPair keyPair, java.lang.String id, int encAlgorithm, char[] passPhrase, PGPSignatureSubpacketVector hashedPcks, PGPSignatureSubpacketVector unhashedPcks, java.security.SecureRandom rand, java.lang.String provider)
           
 
Method Summary
static PGPSecretKey copyWithNewPassword(PGPSecretKey key, char[] oldPassPhrase, char[] newPassPhrase, int newEncAlgorithm, java.security.SecureRandom rand, java.security.Provider provider)
          Return a copy of the passed in secret key, encrypted using a new password and the passed in algorithm.
static PGPSecretKey copyWithNewPassword(PGPSecretKey key, char[] oldPassPhrase, char[] newPassPhrase, int newEncAlgorithm, java.security.SecureRandom rand, java.lang.String provider)
          Return a copy of the passed in secret key, encrypted using a new password and the passed in algorithm.
 void encode(java.io.OutputStream outStream)
           
 PGPPrivateKey extractPrivateKey(char[] passPhrase, java.security.Provider provider)
          Extract a PGPPrivate key from the SecretKey's encrypted contents.
 PGPPrivateKey extractPrivateKey(char[] passPhrase, java.lang.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.
 java.util.Iterator getUserAttributes()
          Return any user attribute vectors associated with the key.
 java.util.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 has an algorithm type that makes it suitable to use for signing.
static PGPSecretKey replacePublicKey(PGPSecretKey secretKey, PGPPublicKey publicKey)
          Replace the passed the public key on the passed in secret key.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PGPSecretKey

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

PGPSecretKey

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

PGPSecretKey

public PGPSecretKey(int certificationLevel,
                    PGPKeyPair keyPair,
                    java.lang.String id,
                    int encAlgorithm,
                    char[] passPhrase,
                    boolean useSHA1,
                    PGPSignatureSubpacketVector hashedPcks,
                    PGPSignatureSubpacketVector unhashedPcks,
                    java.security.SecureRandom rand,
                    java.security.Provider provider)
             throws PGPException
Throws:
PGPException

PGPSecretKey

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

PGPSecretKey

public PGPSecretKey(int certificationLevel,
                    int algorithm,
                    java.security.PublicKey pubKey,
                    java.security.PrivateKey privKey,
                    java.util.Date time,
                    java.lang.String id,
                    int encAlgorithm,
                    char[] passPhrase,
                    boolean useSHA1,
                    PGPSignatureSubpacketVector hashedPcks,
                    PGPSignatureSubpacketVector unhashedPcks,
                    java.security.SecureRandom rand,
                    java.lang.String provider)
             throws PGPException,
                    java.security.NoSuchProviderException
Throws:
PGPException
java.security.NoSuchProviderException
Method Detail

isSigningKey

public boolean isSigningKey()
Return true if this key has an algorithm type that makes it suitable to use for signing.

Note: with version 4 keys KeyFlags subpackets should also be considered when present for determining the preferred use of the key.

Returns:
true if this key algorithm is suitable for use with signing.

isMasterKey

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

Returns:
true if a master key.

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.

getUserIDs

public java.util.Iterator getUserIDs()
Return any userIDs associated with the key.

Returns:
an iterator of Strings.

getUserAttributes

public java.util.Iterator getUserAttributes()
Return any user attribute vectors associated with the key.

Returns:
an iterator of Strings.

extractPrivateKey

public PGPPrivateKey extractPrivateKey(char[] passPhrase,
                                       java.lang.String provider)
                                throws PGPException,
                                       java.security.NoSuchProviderException
Extract a PGPPrivate key from the SecretKey's encrypted contents.

Parameters:
passPhrase -
provider -
Returns:
PGPPrivateKey
Throws:
PGPException
java.security.NoSuchProviderException

extractPrivateKey

public PGPPrivateKey extractPrivateKey(char[] passPhrase,
                                       java.security.Provider provider)
                                throws PGPException
Extract a PGPPrivate key from the SecretKey's encrypted contents.

Parameters:
passPhrase -
provider -
Returns:
PGPPrivateKey
Throws:
PGPException

getEncoded

public byte[] getEncoded()
                  throws java.io.IOException
Throws:
java.io.IOException

encode

public void encode(java.io.OutputStream outStream)
            throws java.io.IOException
Throws:
java.io.IOException

copyWithNewPassword

public static PGPSecretKey copyWithNewPassword(PGPSecretKey key,
                                               char[] oldPassPhrase,
                                               char[] newPassPhrase,
                                               int newEncAlgorithm,
                                               java.security.SecureRandom rand,
                                               java.lang.String provider)
                                        throws PGPException,
                                               java.security.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 - name of the provider to use
Throws:
PGPException
java.security.NoSuchProviderException

copyWithNewPassword

public static PGPSecretKey copyWithNewPassword(PGPSecretKey key,
                                               char[] oldPassPhrase,
                                               char[] newPassPhrase,
                                               int newEncAlgorithm,
                                               java.security.SecureRandom rand,
                                               java.security.Provider provider)
                                        throws PGPException
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
Throws:
PGPException

replacePublicKey

public static PGPSecretKey replacePublicKey(PGPSecretKey secretKey,
                                            PGPPublicKey publicKey)
Replace the passed the public key on the passed in secret key.

Parameters:
secretKey - secret key to change
publicKey - new public key.
Returns:
a new secret key.
Throws:
java.lang.IllegalArgumentException - if keyIDs do not match.

Bouncy Castle Cryptography 1.46