org.neociclo.odetteftp.util
Class EnvelopingUtil

java.lang.Object
  extended by org.neociclo.odetteftp.util.EnvelopingUtil

public class EnvelopingUtil
extends Object

Version:
$Rev: 800 $ $Date: 2010-10-19 20:55:25 -0200 (Tue, 19 Oct 2010) $
Author:
Rafael Marins

Constructor Summary
EnvelopingUtil()
           
 
Method Summary
static void addNotifSignature(DefaultSignedDeliveryNotification notif, CipherSuite cipherSuite, X509Certificate userCert, PrivateKey userPrivateKey)
           
static String asDigestAlgorithm(CipherSuite cs)
           
static String asEncryptionAlgorithm(CipherSuite cipherSuite)
           
static void createCompressedData(File data, File output)
           
static void createCompressedData(InputStream dataStream, OutputStream outStream)
           
static void createCompressedData(String dataPath, String outputPath)
           
static byte[] createEnvelopedData(byte[] content, CipherSuite cipherSel, X509Certificate cert)
          Generate an EnvelopedData object by encrypting the content using the partner's public certificate with the specified CipherSuite.
static void createEnvelopedData(File data, File output, CipherSuite cipherSel, X509Certificate cert)
           
static void createEnvelopedData(InputStream dataStream, OutputStream outStream, CipherSuite cipherSel, X509Certificate cert)
           
static void createEnvelopedData(String dataPath, String outputPath, CipherSuite cipherSel, X509Certificate cert)
           
static void createFileFromCompressedData(File compressedData, File output)
           
static void createFileFromCompressedData(String compressedDataPath, String outputPath)
           
static void createFileFromEnvelopedData(File envelopedData, File output, X509Certificate cert, PrivateKey key)
           
static void createFileFromEnvelopedData(String envelopedDataPath, String outputPath, X509Certificate cert, PrivateKey key)
           
static void createFileFromSignedData(File signedData, File output, X509Certificate cert)
           
static byte[] createSignedData(byte[] content, CipherSuite cipherSuite, X509Certificate cert, PrivateKey key)
          Generate a SignedData object using SHA-1 digest.
static void createSignedData(File data, File output, CipherSuite cipherSuite, X509Certificate cert, PrivateKey key)
           
static void createSignedData(InputStream dataStream, CipherSuite cipherSuite, OutputStream outStream, X509Certificate cert, PrivateKey key)
           
static byte[] getNotifSigningData(SignedDeliveryNotification info)
          Prepare the data buffer for signing from the acknowledge object.
static InputStream openCompressedDataParser(InputStream compressedData)
           
static OutputStream openCompressedDataStreamGenerator(OutputStream outStream)
           
static InputStream openEnvelopedDataParser(InputStream cryptData, X509Certificate cert, PrivateKey key)
           
static OutputStream openEnvelopedDataStreamGenerator(OutputStream outStream, CipherSuite cipherSel, X509Certificate cert)
           
static InputStream openSignedDataParser(InputStream sigData, X509Certificate checkCert)
           
static InputStream openSignedDataParser(InputStream sigData, X509Certificate checkCert, SignatureVerifyResult checkResult)
           
static OutputStream openSignedDataStreamGenerator(OutputStream outStream, CipherSuite cipherSuite, X509Certificate cert, PrivateKey key)
           
static void parseCompressedDataContentStream(InputStream compressedData, OutputStream outStream)
           
static byte[] parseEnvelopedData(byte[] encoded, X509Certificate cert, PrivateKey key)
          Return null if certificate's recipientId could not be found within the encoded envelope - typically when using a bad certificate to decrypt the authentication challenge encrypted using other public certificate.
static void parseEnvelopedDataContentStream(InputStream envelopedStream, OutputStream outStream, X509Certificate cert, PrivateKey key)
           
static byte[] parseSignedData(byte[] encoded)
          Retrieve the signed content from a SignedData object.
static byte[] parseSignedData(byte[] encoded, X509Certificate checkCert, SignatureVerifyResult checkResult)
           
static void parseSignedDataContentStream(InputStream signedStream, OutputStream outStream, X509Certificate cert)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EnvelopingUtil

public EnvelopingUtil()
Method Detail

createEnvelopedData

public static byte[] createEnvelopedData(byte[] content,
                                         CipherSuite cipherSel,
                                         X509Certificate cert)
                                  throws NoSuchAlgorithmException,
                                         NoSuchProviderException,
                                         org.bouncycastle.cms.CMSException,
                                         IOException
Generate an EnvelopedData object by encrypting the content using the partner's public certificate with the specified CipherSuite.

Parameters:
content - the data to be encrypted
cipherSel - ODETTE-FTP like cipher suite selection
cert - partner's public certificate used to produce encrypted data
Returns:
Throws:
NoSuchAlgorithmException
NoSuchProviderException
org.bouncycastle.cms.CMSException
IOException

createEnvelopedData

public static void createEnvelopedData(InputStream dataStream,
                                       OutputStream outStream,
                                       CipherSuite cipherSel,
                                       X509Certificate cert)
                                throws NoSuchAlgorithmException,
                                       NoSuchProviderException,
                                       org.bouncycastle.cms.CMSException,
                                       IOException
Throws:
NoSuchAlgorithmException
NoSuchProviderException
org.bouncycastle.cms.CMSException
IOException

openEnvelopedDataStreamGenerator

public static OutputStream openEnvelopedDataStreamGenerator(OutputStream outStream,
                                                            CipherSuite cipherSel,
                                                            X509Certificate cert)
                                                     throws NoSuchAlgorithmException,
                                                            NoSuchProviderException,
                                                            org.bouncycastle.cms.CMSException,
                                                            IOException
Throws:
NoSuchAlgorithmException
NoSuchProviderException
org.bouncycastle.cms.CMSException
IOException

openEnvelopedDataParser

public static InputStream openEnvelopedDataParser(InputStream cryptData,
                                                  X509Certificate cert,
                                                  PrivateKey key)
                                           throws org.bouncycastle.cms.CMSException,
                                                  IOException,
                                                  NoSuchProviderException
Parameters:
cryptData - InputStream of encapsulated encrypted data
cert - user secure certificate used to match the recipient identifier
key - user private key used to decrypt the encapsulated data
Returns:
InputStream the original data stream (decrypted)
Throws:
org.bouncycastle.cms.CMSException
IOException
NoSuchProviderException

openCompressedDataParser

public static InputStream openCompressedDataParser(InputStream compressedData)
                                            throws org.bouncycastle.cms.CMSException
Parameters:
compressedData - InputStream of encapsulated compressed data
Returns:
InputStream the original (uncompressed) readable data stream
Throws:
org.bouncycastle.cms.CMSException

openSignedDataParser

public static InputStream openSignedDataParser(InputStream sigData,
                                               X509Certificate checkCert)
                                        throws org.bouncycastle.cms.CMSException
Throws:
org.bouncycastle.cms.CMSException

openSignedDataParser

public static InputStream openSignedDataParser(InputStream sigData,
                                               X509Certificate checkCert,
                                               SignatureVerifyResult checkResult)
                                        throws org.bouncycastle.cms.CMSException
Throws:
org.bouncycastle.cms.CMSException

createSignedData

public static void createSignedData(File data,
                                    File output,
                                    CipherSuite cipherSuite,
                                    X509Certificate cert,
                                    PrivateKey key)
                             throws InvalidKeyException,
                                    NoSuchAlgorithmException,
                                    NoSuchProviderException,
                                    org.bouncycastle.cms.CMSException,
                                    IOException
Throws:
InvalidKeyException
NoSuchAlgorithmException
NoSuchProviderException
org.bouncycastle.cms.CMSException
IOException

createSignedData

public static void createSignedData(InputStream dataStream,
                                    CipherSuite cipherSuite,
                                    OutputStream outStream,
                                    X509Certificate cert,
                                    PrivateKey key)
                             throws InvalidKeyException,
                                    NoSuchAlgorithmException,
                                    NoSuchProviderException,
                                    org.bouncycastle.cms.CMSException,
                                    IOException
Throws:
InvalidKeyException
NoSuchAlgorithmException
NoSuchProviderException
org.bouncycastle.cms.CMSException
IOException

openSignedDataStreamGenerator

public static OutputStream openSignedDataStreamGenerator(OutputStream outStream,
                                                         CipherSuite cipherSuite,
                                                         X509Certificate cert,
                                                         PrivateKey key)
                                                  throws NoSuchAlgorithmException,
                                                         NoSuchProviderException,
                                                         org.bouncycastle.cms.CMSException,
                                                         IOException,
                                                         InvalidKeyException
Throws:
NoSuchAlgorithmException
NoSuchProviderException
org.bouncycastle.cms.CMSException
IOException
InvalidKeyException

createEnvelopedData

public static void createEnvelopedData(File data,
                                       File output,
                                       CipherSuite cipherSel,
                                       X509Certificate cert)
                                throws NoSuchAlgorithmException,
                                       NoSuchProviderException,
                                       org.bouncycastle.cms.CMSException,
                                       IOException
Throws:
NoSuchAlgorithmException
NoSuchProviderException
org.bouncycastle.cms.CMSException
IOException

createEnvelopedData

public static void createEnvelopedData(String dataPath,
                                       String outputPath,
                                       CipherSuite cipherSel,
                                       X509Certificate cert)
                                throws NoSuchAlgorithmException,
                                       NoSuchProviderException,
                                       org.bouncycastle.cms.CMSException,
                                       IOException
Throws:
NoSuchAlgorithmException
NoSuchProviderException
org.bouncycastle.cms.CMSException
IOException

createSignedData

public static byte[] createSignedData(byte[] content,
                                      CipherSuite cipherSuite,
                                      X509Certificate cert,
                                      PrivateKey key)
                               throws NoSuchAlgorithmException,
                                      NoSuchProviderException,
                                      org.bouncycastle.cms.CMSException,
                                      IOException
Generate a SignedData object using SHA-1 digest.

Parameters:
content - the data to be signed
cipherSuite -
cert - private certificate used in conjunction with private key
key - private key used to produce the signed-data object
Returns:
the encoded signed-data object
Throws:
NoSuchAlgorithmException
NoSuchProviderException
org.bouncycastle.cms.CMSException
IOException

parseEnvelopedData

public static byte[] parseEnvelopedData(byte[] encoded,
                                        X509Certificate cert,
                                        PrivateKey key)
                                 throws NoSuchProviderException,
                                        org.bouncycastle.cms.CMSException,
                                        IOException
Return null if certificate's recipientId could not be found within the encoded envelope - typically when using a bad certificate to decrypt the authentication challenge encrypted using other public certificate.

Parameters:
encoded -
cert -
key -
Returns:
Throws:
NoSuchProviderException
org.bouncycastle.cms.CMSException
IOException

parseEnvelopedDataContentStream

public static void parseEnvelopedDataContentStream(InputStream envelopedStream,
                                                   OutputStream outStream,
                                                   X509Certificate cert,
                                                   PrivateKey key)
                                            throws NoSuchProviderException,
                                                   org.bouncycastle.cms.CMSException,
                                                   IOException
Throws:
NoSuchProviderException
org.bouncycastle.cms.CMSException
IOException

parseSignedData

public static byte[] parseSignedData(byte[] encoded)
                              throws org.bouncycastle.cms.CMSException
Retrieve the signed content from a SignedData object. Signature MUST BE VERIFIED apart since it's the original data without the signature information.

Parameters:
encoded - the SignedData object
Returns:
the original data from signed content
Throws:
org.bouncycastle.cms.CMSException

parseSignedData

public static byte[] parseSignedData(byte[] encoded,
                                     X509Certificate checkCert,
                                     SignatureVerifyResult checkResult)
                              throws org.bouncycastle.cms.CMSException,
                                     IOException
Throws:
org.bouncycastle.cms.CMSException
IOException

parseSignedDataContentStream

public static void parseSignedDataContentStream(InputStream signedStream,
                                                OutputStream outStream,
                                                X509Certificate cert)
                                         throws org.bouncycastle.cms.CMSException,
                                                IOException
Throws:
org.bouncycastle.cms.CMSException
IOException

createCompressedData

public static void createCompressedData(String dataPath,
                                        String outputPath)
                                 throws IOException
Throws:
IOException

createCompressedData

public static void createCompressedData(File data,
                                        File output)
                                 throws IOException
Throws:
IOException

createCompressedData

public static void createCompressedData(InputStream dataStream,
                                        OutputStream outStream)
                                 throws IOException
Throws:
IOException

openCompressedDataStreamGenerator

public static OutputStream openCompressedDataStreamGenerator(OutputStream outStream)
                                                      throws IOException
Throws:
IOException

createFileFromCompressedData

public static void createFileFromCompressedData(String compressedDataPath,
                                                String outputPath)
                                         throws org.bouncycastle.cms.CMSException,
                                                IOException
Throws:
org.bouncycastle.cms.CMSException
IOException

createFileFromCompressedData

public static void createFileFromCompressedData(File compressedData,
                                                File output)
                                         throws org.bouncycastle.cms.CMSException,
                                                IOException
Throws:
org.bouncycastle.cms.CMSException
IOException

createFileFromEnvelopedData

public static void createFileFromEnvelopedData(String envelopedDataPath,
                                               String outputPath,
                                               X509Certificate cert,
                                               PrivateKey key)
                                        throws NoSuchProviderException,
                                               org.bouncycastle.cms.CMSException,
                                               IOException
Throws:
NoSuchProviderException
org.bouncycastle.cms.CMSException
IOException

createFileFromEnvelopedData

public static void createFileFromEnvelopedData(File envelopedData,
                                               File output,
                                               X509Certificate cert,
                                               PrivateKey key)
                                        throws NoSuchProviderException,
                                               org.bouncycastle.cms.CMSException,
                                               IOException
Throws:
NoSuchProviderException
org.bouncycastle.cms.CMSException
IOException

parseCompressedDataContentStream

public static void parseCompressedDataContentStream(InputStream compressedData,
                                                    OutputStream outStream)
                                             throws org.bouncycastle.cms.CMSException,
                                                    IOException
Throws:
org.bouncycastle.cms.CMSException
IOException

createFileFromSignedData

public static void createFileFromSignedData(File signedData,
                                            File output,
                                            X509Certificate cert)
                                     throws org.bouncycastle.cms.CMSException,
                                            IOException
Throws:
org.bouncycastle.cms.CMSException
IOException

addNotifSignature

public static void addNotifSignature(DefaultSignedDeliveryNotification notif,
                                     CipherSuite cipherSuite,
                                     X509Certificate userCert,
                                     PrivateKey userPrivateKey)
                              throws NoSuchAlgorithmException,
                                     NoSuchProviderException,
                                     IOException,
                                     org.bouncycastle.cms.CMSException
Throws:
NoSuchAlgorithmException
NoSuchProviderException
IOException
org.bouncycastle.cms.CMSException

getNotifSigningData

public static byte[] getNotifSigningData(SignedDeliveryNotification info)
                                  throws UnsupportedEncodingException
Prepare the data buffer for signing from the acknowledge object.

Parameters:
info -
Returns:
Throws:
UnsupportedEncodingException

asEncryptionAlgorithm

public static String asEncryptionAlgorithm(CipherSuite cipherSuite)

asDigestAlgorithm

public static String asDigestAlgorithm(CipherSuite cs)


ACCORD