00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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
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
00097
00098 const String& getAlgorithm() const throw ();
00099 const Provider& getProvider() const throw ();
00100 };
00101 }
00102 }
00103
00104 #endif
00105
00106 #endif