net.sourceforge.jcetaglib.lib
Class Hybrid

java.lang.Object
  extended bynet.sourceforge.jcetaglib.lib.Hybrid

public class Hybrid
extends java.lang.Object

Hybrid encryption & decryption routines for use with BouncyCastle JCE provider

Version:
$Id: Hybrid.java,v 1.3 2004/04/15 07:28:25 hamgert Exp $
Author:
Gert Van Ham, hamgert@users.sourceforge.net, http://jcetaglib.sourceforge.net

Constructor Summary
Hybrid()
           
 
Method Summary
static void decryptAndVerify(java.io.InputStream is, java.io.DataOutputStream daos, java.security.PrivateKey privKey, SignerCertificate signercert, java.lang.String signame, java.lang.String algorithm, java.lang.String mode, java.lang.String padding, int bufferlength)
          decrypt and verify inputstream signature (which must support mark/reset)
static java.lang.StringBuffer decryptAndVerify(java.lang.StringBuffer text, java.security.PrivateKey privKey, SignerCertificate signercert, java.lang.String signame, java.lang.String algorithm, java.lang.String mode, java.lang.String padding)
          decrypt and verify text signature
static void decryptAndVerifyHMAC(java.io.InputStream is, java.io.DataOutputStream daos, java.security.PrivateKey privKey, java.lang.String algorithm, java.lang.String mode, java.lang.String padding, int bufferlength)
          Decrypts and verifies an inputstream (which must support mark/reset) with HMAC
static java.lang.StringBuffer decryptAndVerifyHMAC(java.lang.StringBuffer text, java.security.PrivateKey privKey, java.lang.String algorithm, java.lang.String mode, java.lang.String padding)
          Decrypts and verifies text with HMAC
static void decryptFileAndVerify(java.lang.String file, java.lang.String newfile, java.security.PrivateKey privKey, SignerCertificate signercert, java.lang.String signame, java.lang.String algorithm, java.lang.String mode, java.lang.String padding)
           
static void decryptFileAndVerifyHMAC(java.lang.String file, java.lang.String newfile, java.security.PrivateKey privKey, java.lang.String algorithm, java.lang.String mode, java.lang.String padding)
          Decrypts and verifies file with HMAC
static void encryptAndSign(java.io.InputStream is, java.io.DataOutputStream daos, java.security.PublicKey receiverKey, java.security.PrivateKey signingKey, java.security.cert.X509Certificate cert, java.lang.String signame, java.lang.String algorithm, byte[] seed, int strength, java.lang.String mode, java.lang.String padding, int bufferlength)
          Encrypt and sign any inputstream
static java.lang.StringBuffer encryptAndSign(java.lang.StringBuffer text, java.security.PublicKey receiverKey, java.security.PrivateKey signingKey, java.security.cert.X509Certificate cert, java.lang.String signame, java.lang.String algorithm, byte[] seed, int strength, java.lang.String mode, java.lang.String padding)
          Encrypt and sign a text
static void encryptFileAndSign(java.lang.String file, java.lang.String newfile, java.security.PublicKey receiverKey, java.security.PrivateKey signingKey, java.security.cert.X509Certificate cert, java.lang.String signame, java.lang.String algorithm, byte[] seed, int strength, java.lang.String mode, java.lang.String padding)
          Encrypt and sign a file
static void encryptFileWithHMAC(java.lang.String file, java.lang.String newfile, java.security.PublicKey receiverKey, java.lang.String algorithm, byte[] seed, int strength, java.lang.String mode, java.lang.String padding)
          Encrypts file with an HMAC
static void encryptWithHMAC(java.io.InputStream is, java.io.DataOutputStream daos, java.security.PublicKey receiverKey, java.lang.String algorithm, byte[] seed, int strength, java.lang.String mode, java.lang.String padding, int bufferlength)
          Encrypts any inputstream with an HMAC
static java.lang.StringBuffer encryptWithHMAC(java.lang.StringBuffer text, java.security.PublicKey receiverKey, java.lang.String algorithm, byte[] seed, int strength, java.lang.String mode, java.lang.String padding)
          Encrypts text with an HMAC
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Hybrid

public Hybrid()
Method Detail

encryptWithHMAC

public static java.lang.StringBuffer encryptWithHMAC(java.lang.StringBuffer text,
                                                     java.security.PublicKey receiverKey,
                                                     java.lang.String algorithm,
                                                     byte[] seed,
                                                     int strength,
                                                     java.lang.String mode,
                                                     java.lang.String padding)
                                              throws CryptoException
Encrypts text with an HMAC

Parameters:
text - text to encrypt
receiverKey - the receiver's public key for encrypting the symmetric key
algorithm - encryption algorithm (e.g. "Rijndael")
seed - seed for SecureRandom (optional)
strength - the keysize in bits (e.g. 128)
mode - encryption mode (e.g. "CBC")
padding - padding scheme (e.g."PKCS7Padding")
Returns:
encrypted string in BASE64 format
Throws:
CryptoException - encryption errors

encryptFileWithHMAC

public static void encryptFileWithHMAC(java.lang.String file,
                                       java.lang.String newfile,
                                       java.security.PublicKey receiverKey,
                                       java.lang.String algorithm,
                                       byte[] seed,
                                       int strength,
                                       java.lang.String mode,
                                       java.lang.String padding)
                                throws CryptoException,
                                       java.io.IOException
Encrypts file with an HMAC

Parameters:
file - file to encrypt
newfile - encrypted file
receiverKey - the receiver's public key for encrypting the symmetric key
algorithm - encryption algorithm (e.g. "Rijndael")
seed - seed for SecureRandom (optional)
strength - the keysize in bits (e.g. 128)
mode - encryption mode (e.g. "CBC")
padding - padding scheme (e.g."PKCS7Padding")
Throws:
CryptoException - encryption errors
java.io.IOException - I/O errors

encryptWithHMAC

public static void encryptWithHMAC(java.io.InputStream is,
                                   java.io.DataOutputStream daos,
                                   java.security.PublicKey receiverKey,
                                   java.lang.String algorithm,
                                   byte[] seed,
                                   int strength,
                                   java.lang.String mode,
                                   java.lang.String padding,
                                   int bufferlength)
                            throws CryptoException,
                                   java.io.IOException
Encrypts any inputstream with an HMAC

Parameters:
is - inputstream to encrypt
daos - outputstream to store the encrypted data
receiverKey - the receiver's public key for encrypting the symmetric key
algorithm - encryption algorithm (e.g. "Rijndael")
seed - seed for SecureRandom (optional)
strength - the keysize in bits (e.g. 128)
mode - encryption mode (e.g. "CBC")
padding - padding scheme (e.g."PKCS7Padding")
bufferlength - buffer length in bytes
Throws:
CryptoException - encryption errors
java.io.IOException - I/O errors

decryptAndVerifyHMAC

public static java.lang.StringBuffer decryptAndVerifyHMAC(java.lang.StringBuffer text,
                                                          java.security.PrivateKey privKey,
                                                          java.lang.String algorithm,
                                                          java.lang.String mode,
                                                          java.lang.String padding)
                                                   throws HeaderException,
                                                          InvalidHMACException,
                                                          CryptoException
Decrypts and verifies text with HMAC

Parameters:
text - the text to decrypt
privKey - the receiver's private key for decryption
algorithm - encryption algorithm (e.g. "Rijndael")
mode - encryption mode (e.g. "CBC")
padding - padding scheme (e.g."PKCS7Padding")
Returns:
deciphered text
Throws:
HeaderException - thrown when package header is broken
InvalidHMACException - thrown when the HMAC code is invalid
CryptoException - all encryption errors

decryptFileAndVerifyHMAC

public static void decryptFileAndVerifyHMAC(java.lang.String file,
                                            java.lang.String newfile,
                                            java.security.PrivateKey privKey,
                                            java.lang.String algorithm,
                                            java.lang.String mode,
                                            java.lang.String padding)
                                     throws CryptoException,
                                            HeaderException,
                                            InvalidHMACException,
                                            java.io.IOException
Decrypts and verifies file with HMAC

Parameters:
file - the file to decrypt
newfile - the decrypted file
privKey - the receiver's private key for decryption
algorithm - encryption algorithm (e.g. "Rijndael")
mode - encryption mode (e.g. "CBC")
padding - padding scheme (e.g."PKCS7Padding")
Throws:
java.io.IOException - I/O errors
HeaderException - thrown when package header is broken
InvalidHMACException - thrown when the HMAC code is invalid
CryptoException - all encryption errors

decryptAndVerifyHMAC

public static void decryptAndVerifyHMAC(java.io.InputStream is,
                                        java.io.DataOutputStream daos,
                                        java.security.PrivateKey privKey,
                                        java.lang.String algorithm,
                                        java.lang.String mode,
                                        java.lang.String padding,
                                        int bufferlength)
                                 throws java.io.IOException,
                                        HeaderException,
                                        InvalidHMACException,
                                        CryptoException
Decrypts and verifies an inputstream (which must support mark/reset) with HMAC

Parameters:
is - inputstream to decrypt (NOTE: the inputstream must support mark/reset because it must be read three times)
daos - outputstream to store the decrypted data
privKey - the receiver's private key for decryption
algorithm - encryption algorithm (e.g. "Rijndael")
mode - encryption mode (e.g. "CBC")
padding - padding scheme (e.g."PKCS7Padding")
bufferlength - buffer length in bytes
Throws:
java.io.IOException - I/O errors
HeaderException - thrown when package header is broken
InvalidHMACException - thrown when the HMAC code is invalid
CryptoException - all encryption errors

encryptAndSign

public static java.lang.StringBuffer encryptAndSign(java.lang.StringBuffer text,
                                                    java.security.PublicKey receiverKey,
                                                    java.security.PrivateKey signingKey,
                                                    java.security.cert.X509Certificate cert,
                                                    java.lang.String signame,
                                                    java.lang.String algorithm,
                                                    byte[] seed,
                                                    int strength,
                                                    java.lang.String mode,
                                                    java.lang.String padding)
                                             throws CryptoException
Encrypt and sign a text

Parameters:
text - the text to encrypt and sign
receiverKey - the public key of the receiver
signingKey - the private key of the signer
cert - the signer's certificate
signame - the signature's algorithm (e.g."MD5withRSA")
algorithm - encryption algorithm (e.g. "Rijndael")
seed - for SecureRandom (optional)
strength - the keysize in bits (e.g. 128)
mode - encryption mode (e.g. "CBC")
padding - padding scheme (e.g."PKCS7Padding")
Returns:
ciphered and signed text
Throws:
CryptoException - encryption errors

encryptFileAndSign

public static void encryptFileAndSign(java.lang.String file,
                                      java.lang.String newfile,
                                      java.security.PublicKey receiverKey,
                                      java.security.PrivateKey signingKey,
                                      java.security.cert.X509Certificate cert,
                                      java.lang.String signame,
                                      java.lang.String algorithm,
                                      byte[] seed,
                                      int strength,
                                      java.lang.String mode,
                                      java.lang.String padding)
                               throws CryptoException,
                                      java.io.IOException
Encrypt and sign a file

Parameters:
file - file to encrypt
newfile - encrypted file
receiverKey - the public key of the receiver
signingKey - the private key of the signer
cert - the signer's certificate
signame - the signature's algorithm (e.g."MD5withRSA")
algorithm - encryption algorithm (e.g. "Rijndael")
seed - for SecureRandom (optional)
strength - the keysize in bits (e.g. 128)
mode - encryption mode (e.g. "CBC")
padding - padding scheme (e.g."PKCS7Padding")
Throws:
CryptoException - encryption errors
java.io.IOException - I/O errors

encryptAndSign

public static void encryptAndSign(java.io.InputStream is,
                                  java.io.DataOutputStream daos,
                                  java.security.PublicKey receiverKey,
                                  java.security.PrivateKey signingKey,
                                  java.security.cert.X509Certificate cert,
                                  java.lang.String signame,
                                  java.lang.String algorithm,
                                  byte[] seed,
                                  int strength,
                                  java.lang.String mode,
                                  java.lang.String padding,
                                  int bufferlength)
                           throws CryptoException,
                                  java.io.IOException
Encrypt and sign any inputstream

Parameters:
is - inputstream to encrypt
daos - outputstream to store the encrypted & signed data
receiverKey - the public key of the receiver
signingKey - the private key of the signer
cert - the signer's certificate
signame - the signature's algorithm (e.g."MD5withRSA")
algorithm - encryption algorithm (e.g. "Rijndael")
seed - for SecureRandom (optional)
strength - the keysize in bits (e.g. 128)
mode - encryption mode (e.g. "CBC")
padding - padding scheme (e.g."PKCS7Padding")
bufferlength - buffer length in bytes
Throws:
CryptoException - encryption errors
java.io.IOException - I/O errors

decryptAndVerify

public static java.lang.StringBuffer decryptAndVerify(java.lang.StringBuffer text,
                                                      java.security.PrivateKey privKey,
                                                      SignerCertificate signercert,
                                                      java.lang.String signame,
                                                      java.lang.String algorithm,
                                                      java.lang.String mode,
                                                      java.lang.String padding)
                                               throws HeaderException,
                                                      InvalidSignatureException,
                                                      CryptoException
decrypt and verify text signature

Parameters:
text - the text to decrypt and verify
privKey - the private key of the receiver
signercert - returns the signer's certificate
signame - the signature's algorithm (e.g."MD5withRSA")
algorithm - encryption algorithm (e.g. "Rijndael")
mode - encryption mode (e.g. "CBC")
padding - padding scheme (e.g."PKCS7Padding")
Returns:
the plaintext
Throws:
HeaderException - thrown when package header is broken
InvalidSignatureException - thrown when the signature is invalid
CryptoException - all encryption errors

decryptAndVerify

public static void decryptAndVerify(java.io.InputStream is,
                                    java.io.DataOutputStream daos,
                                    java.security.PrivateKey privKey,
                                    SignerCertificate signercert,
                                    java.lang.String signame,
                                    java.lang.String algorithm,
                                    java.lang.String mode,
                                    java.lang.String padding,
                                    int bufferlength)
                             throws CryptoException,
                                    HeaderException,
                                    InvalidSignatureException,
                                    java.io.IOException
decrypt and verify inputstream signature (which must support mark/reset)

Parameters:
is - the inputstream to decrypt and verify (NOTE: the inputstream must support mark/reset because it must be read three times)
daos - the outputstream containing the deciphered data
privKey - the private key of the receiver
signercert - returns the signer's certificate
signame - the signature's algorithm (e.g."MD5withRSA")
algorithm - encryption algorithm (e.g. "Rijndael")
mode - encryption mode (e.g. "CBC")
padding - padding scheme (e.g."PKCS7Padding")
bufferlength - buffer length in bytes
Throws:
java.io.IOException - I/O errors
HeaderException - thrown when package header is broken
InvalidSignatureException - thrown when the signature is invalid
CryptoException - all encryption errors

decryptFileAndVerify

public static void decryptFileAndVerify(java.lang.String file,
                                        java.lang.String newfile,
                                        java.security.PrivateKey privKey,
                                        SignerCertificate signercert,
                                        java.lang.String signame,
                                        java.lang.String algorithm,
                                        java.lang.String mode,
                                        java.lang.String padding)
                                 throws CryptoException,
                                        HeaderException,
                                        InvalidSignatureException,
                                        java.io.IOException
Parameters:
file - the file to decrypt and verify
newfile - the decrypted file
privKey - the private key of the receiver
signercert - returns the signer's certificate
signame - the signature's algorithm (e.g."MD5withRSA")
algorithm - encryption algorithm (e.g. "Rijndael")
mode - encryption mode (e.g. "CBC")
padding - padding scheme (e.g."PKCS7Padding")
Throws:
java.io.IOException - I/O errors
HeaderException - thrown when package header is broken
InvalidSignatureException - thrown when the signature is invalid
CryptoException - all encryption errors