net.suberic.crypto
Class PGPEncryptionUtils

java.lang.Object
  extended bynet.suberic.crypto.EncryptionUtils
      extended bynet.suberic.crypto.PGPEncryptionUtils

public class PGPEncryptionUtils
extends EncryptionUtils

Utilities for encrypting/decrypting messages. This class just handles the parsing of the OpenPGP message itself. Actual PGP encoding/decoding is left to the PGPProviderImpl class itself.


Field Summary
 
Fields inherited from class net.suberic.crypto.EncryptionUtils
ATTACHED_KEYS, ENCRYPTED, NOT_ENCRYPTED, SIGNED
 
Constructor Summary
PGPEncryptionUtils()
           
 
Method Summary
 boolean checkSignature(java.io.InputStream rawStream, byte[] signature, java.security.Key key)
          Checks a signature against a section of text.
 boolean checkSignature(javax.mail.internet.MimeMessage mm, java.security.Key key)
          Checks the signature on a MimeMessage.
 boolean checkSignature(javax.mail.internet.MimeMultipart mMulti, java.security.Key key)
          Checks the signature on a BodyPart.
 boolean checkSignature(javax.mail.internet.MimePart part, java.security.Key key)
          Checks the signature on a MimePart.
protected  javax.mail.internet.MimeBodyPart createEncryptedPart(java.io.InputStream stream, java.security.Key key)
          Makes an encrypted BodyPart from the content in the given InputStream.
 EncryptionKeyManager createKeyManager()
          Returns a KeyStore provider.
 EncryptionKeyManager createKeyManager(java.io.InputStream inputStream, char[] password)
          Returns a KeyStore provider.
 javax.mail.internet.MimeBodyPart createPublicKeyPart(java.security.Key[] keys)
          Packages up the public keys in a form to be sent as a public key message.
 byte[] decrypt(java.io.InputStream encryptedStream, java.security.Key key)
          Decrypts a section of text using an java.security.Key.
 javax.mail.internet.MimeBodyPart decryptBodyPart(javax.mail.internet.MimeBodyPart part, java.security.Key key)
          Decrypts a MimeBodyPart.
 javax.mail.internet.MimeMessage decryptMessage(javax.mail.Session s, javax.mail.internet.MimeMessage msg, java.security.Key key)
          Decrypts a Message.
 javax.mail.internet.MimeBodyPart decryptMultipart(javax.mail.internet.MimeMultipart mpart, java.security.Key key)
          Decrypts a Multipart.
 byte[] encrypt(java.io.InputStream rawStream, java.security.Key key)
          Encrypts a section of text using an java.security.Key.
 javax.mail.internet.MimeMessage encryptMessage(javax.mail.Session s, javax.mail.internet.MimeMessage msg, java.security.Key key)
          Encrypts a Message.
 javax.mail.internet.MimeBodyPart encryptPart(javax.mail.internet.MimeBodyPart part, java.security.Key key)
          Encrypts a MimeBodyPart;
 java.security.Key[] extractKeys(java.io.InputStream rawStream)
          Extracts public key information.
 java.security.Key[] extractKeys(javax.mail.internet.MimeBodyPart mbp)
          Extracts public key information.
 java.security.Key[] extractKeys(javax.mail.internet.MimeMessage m)
          Extracts public key information.
 int getEncryptionStatus(javax.mail.internet.MimePart m)
          Returns the encryption status of this MimeMessage: ENCRYPTED, SIGNED, or NOT_ENCRYPTED.
 PGPProviderImpl getPGPProviderImpl()
          Returns the PGPProviderImpl.
 javax.mail.internet.MimeBodyPart getSignedContent(javax.mail.internet.MimePart mp)
          Returns the signed body part.
 java.lang.String getType()
          Returns the encryption type that these utils are implementing (PGP or SMIME).
 byte[] packageKeys(java.security.Key[] keys)
          Packages up the public keys in a form to be sent as a public key message.
 void setPGPProviderImpl(PGPProviderImpl newPgpImpl)
          Sets the PGPProviderImpl.
 byte[] sign(java.io.InputStream rawStream, java.security.Key key)
          Signs a section of text.
 javax.mail.internet.MimeBodyPart signBodyPart(javax.mail.internet.MimeBodyPart mbp, java.security.Key key)
          Signs a MimeBodyPart.
 javax.mail.internet.MimeMessage signMessage(javax.mail.Session s, javax.mail.internet.MimeMessage msg, java.security.Key key)
          Signs a Message.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PGPEncryptionUtils

public PGPEncryptionUtils()
Method Detail

getPGPProviderImpl

public PGPProviderImpl getPGPProviderImpl()
Returns the PGPProviderImpl.


setPGPProviderImpl

public void setPGPProviderImpl(PGPProviderImpl newPgpImpl)
Sets the PGPProviderImpl.


decrypt

public byte[] decrypt(java.io.InputStream encryptedStream,
                      java.security.Key key)
               throws java.security.NoSuchAlgorithmException,
                      java.io.IOException,
                      java.security.GeneralSecurityException
Decrypts a section of text using an java.security.Key.

Throws:
java.security.NoSuchAlgorithmException
java.io.IOException
java.security.GeneralSecurityException

encrypt

public byte[] encrypt(java.io.InputStream rawStream,
                      java.security.Key key)
               throws java.security.NoSuchAlgorithmException,
                      java.io.IOException,
                      java.security.GeneralSecurityException
Encrypts a section of text using an java.security.Key.

Throws:
java.security.NoSuchAlgorithmException
java.io.IOException
java.security.GeneralSecurityException

sign

public byte[] sign(java.io.InputStream rawStream,
                   java.security.Key key)
            throws java.security.NoSuchAlgorithmException,
                   java.io.IOException,
                   java.security.GeneralSecurityException
Signs a section of text.

Throws:
java.security.NoSuchAlgorithmException
java.io.IOException
java.security.GeneralSecurityException

checkSignature

public boolean checkSignature(java.io.InputStream rawStream,
                              byte[] signature,
                              java.security.Key key)
                       throws java.security.NoSuchAlgorithmException,
                              java.io.IOException,
                              java.security.GeneralSecurityException
Checks a signature against a section of text.

Throws:
java.security.NoSuchAlgorithmException
java.io.IOException
java.security.GeneralSecurityException

extractKeys

public java.security.Key[] extractKeys(java.io.InputStream rawStream)
                                throws java.security.GeneralSecurityException,
                                       java.io.IOException
Extracts public key information.

Throws:
java.security.GeneralSecurityException
java.io.IOException

packageKeys

public byte[] packageKeys(java.security.Key[] keys)
                   throws java.security.GeneralSecurityException,
                          java.io.IOException
Packages up the public keys in a form to be sent as a public key message.

Throws:
java.security.GeneralSecurityException
java.io.IOException

encryptMessage

public javax.mail.internet.MimeMessage encryptMessage(javax.mail.Session s,
                                                      javax.mail.internet.MimeMessage msg,
                                                      java.security.Key key)
                                               throws javax.mail.MessagingException,
                                                      java.io.IOException,
                                                      java.security.GeneralSecurityException
Encrypts a Message.

Specified by:
encryptMessage in class EncryptionUtils
Throws:
javax.mail.MessagingException
java.io.IOException
java.security.GeneralSecurityException

decryptMessage

public javax.mail.internet.MimeMessage decryptMessage(javax.mail.Session s,
                                                      javax.mail.internet.MimeMessage msg,
                                                      java.security.Key key)
                                               throws javax.mail.MessagingException,
                                                      java.io.IOException,
                                                      java.security.GeneralSecurityException
Decrypts a Message.

Specified by:
decryptMessage in class EncryptionUtils
Throws:
javax.mail.MessagingException
java.io.IOException
java.security.GeneralSecurityException

encryptPart

public javax.mail.internet.MimeBodyPart encryptPart(javax.mail.internet.MimeBodyPart part,
                                                    java.security.Key key)
                                             throws javax.mail.MessagingException,
                                                    java.security.GeneralSecurityException,
                                                    java.io.IOException
Encrypts a MimeBodyPart;

Specified by:
encryptPart in class EncryptionUtils
Throws:
javax.mail.MessagingException
java.security.GeneralSecurityException
java.io.IOException

createEncryptedPart

protected javax.mail.internet.MimeBodyPart createEncryptedPart(java.io.InputStream stream,
                                                               java.security.Key key)
                                                        throws javax.mail.MessagingException,
                                                               java.io.IOException,
                                                               java.security.GeneralSecurityException
Makes an encrypted BodyPart from the content in the given InputStream.

Throws:
javax.mail.MessagingException
java.io.IOException
java.security.GeneralSecurityException

decryptBodyPart

public javax.mail.internet.MimeBodyPart decryptBodyPart(javax.mail.internet.MimeBodyPart part,
                                                        java.security.Key key)
                                                 throws javax.mail.MessagingException,
                                                        java.io.IOException,
                                                        java.security.GeneralSecurityException
Decrypts a MimeBodyPart.

Specified by:
decryptBodyPart in class EncryptionUtils
Throws:
javax.mail.MessagingException
java.io.IOException
java.security.GeneralSecurityException

decryptMultipart

public javax.mail.internet.MimeBodyPart decryptMultipart(javax.mail.internet.MimeMultipart mpart,
                                                         java.security.Key key)
                                                  throws javax.mail.MessagingException,
                                                         java.io.IOException,
                                                         java.security.GeneralSecurityException
Decrypts a Multipart.

Specified by:
decryptMultipart in class EncryptionUtils
Throws:
javax.mail.MessagingException
java.io.IOException
java.security.GeneralSecurityException

signBodyPart

public javax.mail.internet.MimeBodyPart signBodyPart(javax.mail.internet.MimeBodyPart mbp,
                                                     java.security.Key key)
                                              throws javax.mail.MessagingException,
                                                     java.io.IOException,
                                                     java.security.GeneralSecurityException
Signs a MimeBodyPart.

Specified by:
signBodyPart in class EncryptionUtils
Throws:
javax.mail.MessagingException
java.io.IOException
java.security.GeneralSecurityException

checkSignature

public boolean checkSignature(javax.mail.internet.MimeMessage mm,
                              java.security.Key key)
                       throws javax.mail.MessagingException,
                              java.io.IOException,
                              java.security.GeneralSecurityException
Checks the signature on a MimeMessage.

Specified by:
checkSignature in class EncryptionUtils
Throws:
javax.mail.MessagingException
java.io.IOException
java.security.GeneralSecurityException

signMessage

public javax.mail.internet.MimeMessage signMessage(javax.mail.Session s,
                                                   javax.mail.internet.MimeMessage msg,
                                                   java.security.Key key)
                                            throws javax.mail.MessagingException,
                                                   java.io.IOException,
                                                   java.security.GeneralSecurityException
Signs a Message.

Specified by:
signMessage in class EncryptionUtils
Throws:
javax.mail.MessagingException
java.io.IOException
java.security.GeneralSecurityException

checkSignature

public boolean checkSignature(javax.mail.internet.MimePart part,
                              java.security.Key key)
                       throws javax.mail.MessagingException,
                              java.io.IOException,
                              java.security.GeneralSecurityException
Checks the signature on a MimePart.

Specified by:
checkSignature in class EncryptionUtils
Throws:
javax.mail.MessagingException
java.io.IOException
java.security.GeneralSecurityException

checkSignature

public boolean checkSignature(javax.mail.internet.MimeMultipart mMulti,
                              java.security.Key key)
                       throws javax.mail.MessagingException,
                              java.io.IOException,
                              java.security.GeneralSecurityException
Checks the signature on a BodyPart.

Specified by:
checkSignature in class EncryptionUtils
Throws:
javax.mail.MessagingException
java.io.IOException
java.security.GeneralSecurityException

getSignedContent

public javax.mail.internet.MimeBodyPart getSignedContent(javax.mail.internet.MimePart mp)
                                                  throws javax.mail.MessagingException,
                                                         java.io.IOException
Returns the signed body part.

Specified by:
getSignedContent in class EncryptionUtils
Throws:
javax.mail.MessagingException
java.io.IOException

extractKeys

public java.security.Key[] extractKeys(javax.mail.internet.MimeMessage m)
                                throws javax.mail.MessagingException,
                                       java.io.IOException,
                                       java.security.GeneralSecurityException
Extracts public key information.

Specified by:
extractKeys in class EncryptionUtils
Throws:
javax.mail.MessagingException
java.io.IOException
java.security.GeneralSecurityException

extractKeys

public java.security.Key[] extractKeys(javax.mail.internet.MimeBodyPart mbp)
                                throws javax.mail.MessagingException,
                                       java.io.IOException,
                                       java.security.GeneralSecurityException
Extracts public key information.

Specified by:
extractKeys in class EncryptionUtils
Throws:
javax.mail.MessagingException
java.io.IOException
java.security.GeneralSecurityException

createPublicKeyPart

public javax.mail.internet.MimeBodyPart createPublicKeyPart(java.security.Key[] keys)
                                                     throws javax.mail.MessagingException,
                                                            java.io.IOException,
                                                            java.security.GeneralSecurityException
Packages up the public keys in a form to be sent as a public key message.

Specified by:
createPublicKeyPart in class EncryptionUtils
Throws:
javax.mail.MessagingException
java.io.IOException
java.security.GeneralSecurityException

createKeyManager

public EncryptionKeyManager createKeyManager()
Returns a KeyStore provider.

Specified by:
createKeyManager in class EncryptionUtils

createKeyManager

public EncryptionKeyManager createKeyManager(java.io.InputStream inputStream,
                                             char[] password)
                                      throws java.io.IOException,
                                             java.security.KeyStoreException,
                                             java.security.NoSuchAlgorithmException,
                                             java.security.NoSuchProviderException,
                                             java.security.cert.CertificateException
Returns a KeyStore provider.

Throws:
java.io.IOException
java.security.KeyStoreException
java.security.NoSuchAlgorithmException
java.security.NoSuchProviderException
java.security.cert.CertificateException

getEncryptionStatus

public int getEncryptionStatus(javax.mail.internet.MimePart m)
                        throws javax.mail.MessagingException
Returns the encryption status of this MimeMessage: ENCRYPTED, SIGNED, or NOT_ENCRYPTED.

Specified by:
getEncryptionStatus in class EncryptionUtils
Throws:
javax.mail.MessagingException

getType

public java.lang.String getType()
Returns the encryption type that these utils are implementing (PGP or SMIME).

Specified by:
getType in class EncryptionUtils