c++/crypto/Cipher.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2004 Beeyond Software Holding 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_CIPHER_H
00024 #define _CLASS_CIPHER_H
00025 
00026 #ifdef __cplusplus
00027 
00028 #include "beecrypt/c++/crypto/CipherSpi.h"
00029 using beecrypt::crypto::CipherSpi;
00030 #include "beecrypt/c++/crypto/NoSuchPaddingException.h"
00031 using beecrypt::crypto::NoSuchPaddingException;
00032 #include "beecrypt/c++/lang/Object.h"
00033 using beecrypt::lang::Object;
00034 #include "beecrypt/c++/security/Provider.h"
00035 using beecrypt::security::Provider;
00036 #include "beecrypt/c++/security/NoSuchAlgorithmException.h"
00037 using beecrypt::security::NoSuchAlgorithmException;
00038 #include "beecrypt/c++/security/NoSuchProviderException.h"
00039 using beecrypt::security::NoSuchProviderException;
00040 #include "beecrypt/c++/security/cert/Certificate.h"
00041 using beecrypt::security::cert::Certificate;
00042 
00043 namespace beecrypt {
00044     namespace crypto {
00047         class BEECRYPTCXXAPI Cipher : public beecrypt::lang::Object
00048         {
00049         public:
00050             static Cipher* getInstance(const String& transformation) throw (NoSuchAlgorithmException, NoSuchPaddingException);
00051             static Cipher* getInstance(const String& transformation, const String& provider) throw (NoSuchAlgorithmException, NoSuchProviderException, NoSuchPaddingException);
00052             static Cipher* getInstance(const String& transformation, const Provider& provider) throw (NoSuchAlgorithmException, NoSuchPaddingException);
00053 
00054             static const int ENCRYPT_MODE;
00055             static const int DECRYPT_MODE;
00056             static const int WRAP_MODE;
00057             static const int UNWRAP_MODE;
00058 
00059             static size_t getMaxAllowedKeyLength(const String& transformation) throw (NoSuchAlgorithmException);
00060             static AlgorithmParameterSpec* getMaxAllowedParameterSpec(const String& transformation) throw (NoSuchAlgorithmException);
00061 
00062         private:
00063             CipherSpi*      _cspi;
00064             String          _algo;
00065             const Provider* _prov;
00066             bool            _init;
00067 
00068         protected:
00069             Cipher(CipherSpi* cipherSpi, const Provider* provider, const String& transformation);
00070 
00071         public:
00072             virtual ~Cipher();
00073 
00074             bytearray* doFinal() throw (IllegalStateException, IllegalBlockSizeException, BadPaddingException);
00075             bytearray* doFinal(const bytearray& input) throw (IllegalStateException, IllegalBlockSizeException, BadPaddingException);
00076             size_t doFinal(bytearray& output, size_t outputOffset) throw (IllegalStateException, IllegalBlockSizeException, ShortBufferException, BadPaddingException);
00077             bytearray* doFinal(const byte* input, size_t inputOffset, size_t inputLength) throw (IllegalStateException, IllegalBlockSizeException, BadPaddingException);
00078             size_t doFinal(const byte* input, size_t inputOffset, size_t inputLength, bytearray& output, size_t outputOffset = 0) throw (IllegalStateException, IllegalBlockSizeException, ShortBufferException, BadPaddingException);
00079 //          virtual size_t doFinal(ByteBuffer& input, ByteBuffer& output) throw (IllegalStateException, ShortBufferException, BadPaddingException);
00080 
00081             size_t getBlockSize() const throw ();
00082             size_t getKeySize() const throw ();
00083             size_t getOutputSize(size_t inputLength) throw ();
00084             AlgorithmParameters* getParameters() throw ();
00085 
00086             bytearray* getIV();
00087 
00088             void init(int opmode, const Certificate& certificate, SecureRandom* random = 0) throw (InvalidKeyException);
00089             void init(int opmode, const Key& key, SecureRandom* random = 0) throw (InvalidKeyException);
00090             void init(int opmode, const Key& key, AlgorithmParameters* params, SecureRandom* random = 0) throw (InvalidKeyException, InvalidAlgorithmParameterException);
00091             void init(int opmode, const Key& key, const AlgorithmParameterSpec& params, SecureRandom* random = 0) throw (InvalidKeyException, InvalidAlgorithmParameterException);
00092 
00093             bytearray* update(const bytearray& input) throw (IllegalStateException);
00094             bytearray* update(const byte* input, size_t inputOffset, size_t inputLength) throw (IllegalStateException);
00095             size_t update(const byte* input, size_t inputOffset, size_t inputLength, bytearray& output, size_t outputOffset = 0) throw (IllegalStateException, ShortBufferException);
00096 //          size_t update(ByteBuffer& input, ByteBuffer& output) throw (IllegalStateException, ShortBufferException);
00097 
00098             const String& getAlgorithm() const throw ();
00099             const Provider& getProvider() const throw ();
00100         };
00101     }
00102 }
00103 
00104 #endif
00105 
00106 #endif

Generated on Wed Aug 22 06:28:00 2007 for BeeCrypt by  doxygen 1.5.2