00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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
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
00089
00090 const String& getAlgorithm() const throw ();
00091 const Provider& getProvider() const throw ();
00092 };
00093 }
00094 }
00095
00096 #endif
00097
00098 #endif