Cipher.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2004 X-Way Rights BV
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2.1 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Lesser General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public
00015  * License along with this library; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017  */
00018 
00023 #ifndef _CLASS_BEE_CRYPTO_CIPHER_H
00024 #define _CLASS_BEE_CRYPTO_CIPHER_H
00025 
00026 #ifdef __cplusplus
00027 
00028 #include "beecrypt/c++/crypto/CipherSpi.h"
00029 using beecrypt::crypto::CipherSpi;
00030 #include "beecrypt/c++/security/Provider.h"
00031 using beecrypt::security::Provider;
00032 #include "beecrypt/c++/security/cert/Certificate.h"
00033 using beecrypt::security::cert::Certificate;
00034 
00035 namespace beecrypt {
00036     namespace crypto {
00039         class BEECRYPTCXXAPI Cipher : public Object
00040         {
00041         public:
00042             static Cipher* getInstance(const String& transformation) throw (NoSuchAlgorithmException, NoSuchPaddingException);
00043             static Cipher* getInstance(const String& transformation, const String& provider) throw (NoSuchAlgorithmException, NoSuchProviderException, NoSuchPaddingException);
00044             static Cipher* getInstance(const String& transformation, const Provider& provider) throw (NoSuchAlgorithmException, NoSuchPaddingException);
00045 
00046             static const int ENCRYPT_MODE;
00047             static const int DECRYPT_MODE;
00048             static const int WRAP_MODE;
00049             static const int UNWRAP_MODE;
00050 
00051             static int getMaxAllowedKeyLength(const String& transformation) throw (NoSuchAlgorithmException);
00052             static AlgorithmParameterSpec* getMaxAllowedParameterSpec(const String& transformation) throw (NoSuchAlgorithmException);
00053 
00054         private:
00055             CipherSpi*      _cspi;
00056             String          _algo;
00057             const Provider* _prov;
00058             bool            _init;
00059 
00060         protected:
00061             Cipher(CipherSpi* cipherSpi, const Provider* provider, const String& transformation);
00062 
00063         public:
00064             virtual ~Cipher();
00065 
00066             bytearray* doFinal() throw (IllegalStateException, IllegalBlockSizeException, BadPaddingException);
00067             bytearray* doFinal(const bytearray& input) throw (IllegalStateException, IllegalBlockSizeException, BadPaddingException);
00068             int doFinal(bytearray& output, int outputOffset) throw (IllegalStateException, IllegalBlockSizeException, ShortBufferException, BadPaddingException);
00069             bytearray* doFinal(const byte* input, int inputOffset, int inputLength) throw (IllegalStateException, IllegalBlockSizeException, BadPaddingException);
00070             int doFinal(const byte* input, int inputOffset, int inputLength, bytearray& output, int outputOffset = 0) throw (IllegalStateException, IllegalBlockSizeException, ShortBufferException, BadPaddingException);
00071 //          virtual int doFinal(ByteBuffer& input, ByteBuffer& output) throw (IllegalStateException, ShortBufferException, BadPaddingException);
00072 
00073             int getBlockSize() const throw ();
00074             int getKeySize() const throw ();
00075             int getOutputSize(int inputLength) throw ();
00076             AlgorithmParameters* getParameters() throw ();
00077 
00078             bytearray* getIV();
00079 
00080             void init(int opmode, const Certificate& certificate, SecureRandom* random = 0) throw (InvalidKeyException);
00081             void init(int opmode, const Key& key, SecureRandom* random = 0) throw (InvalidKeyException);
00082             void init(int opmode, const Key& key, AlgorithmParameters* params, SecureRandom* random = 0) throw (InvalidKeyException, InvalidAlgorithmParameterException);
00083             void init(int opmode, const Key& key, const AlgorithmParameterSpec& params, SecureRandom* random = 0) throw (InvalidKeyException, InvalidAlgorithmParameterException);
00084 
00085             bytearray* update(const bytearray& input) throw (IllegalStateException);
00086             bytearray* update(const byte* input, int inputOffset, int inputLength) throw (IllegalStateException);
00087             int update(const byte* input, int inputOffset, int inputLength, bytearray& output, int outputOffset = 0) throw (IllegalStateException, ShortBufferException);
00088 //          int update(ByteBuffer& input, ByteBuffer& output) throw (IllegalStateException, ShortBufferException);
00089 
00090             const String& getAlgorithm() const throw ();
00091             const Provider& getProvider() const throw ();
00092         };
00093     }
00094 }
00095 
00096 #endif
00097 
00098 #endif

Generated on Fri Jun 19 13:39:39 2009 for BeeCrypt C++ by  doxygen 1.5.8