• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

spl/Des.h

00001 /*
00002  *   This file is part of the Standard Portable Library (SPL).
00003  *
00004  *   SPL is free software: you can redistribute it and/or modify
00005  *   it under the terms of the GNU General Public License as published by
00006  *   the Free Software Foundation, either version 3 of the License, or
00007  *   (at your option) any later version.
00008  *
00009  *   SPL 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
00012  *   GNU General Public License for more details.
00013  *
00014  *   You should have received a copy of the GNU General Public License
00015  *   along with SPL.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 #ifndef _des_h
00018 #define _des_h
00019 
00020 #include <spl/types.h>
00021 #include <spl/Debug.h>
00022 #include <spl/collection/Array.h>
00023 #include <spl/RefCountPtr.h>
00024 #include <spl/String.h>
00025 
00034 typedef struct _des_ctx
00035 {
00036     uint32 encrypt_subkeys[32];
00037     uint32 decrypt_subkeys[32];
00038 } des_ctx[1];
00039 
00040 #include <spl/String.h>
00041 
00045 class DES
00046 {
00047 private:
00048         // forbid copy constructor
00049         inline DES(const DES& pmp) {}
00050         inline void operator =(const DES& pmp) {}
00051 
00052 protected:
00053         des_ctx m_ctx;
00054 
00055 public:
00056         DES(const String& password);
00057         void EncryptBinary(const Array<byte>& data, Array<byte>& output);
00058         void DecryptBinary(Array<byte>& data);
00059         RefCountPtr<Array<byte> > DecryptString(const String& data);
00060         RefCountPtr<String> EncryptString(const Array<byte>& data);
00061 
00062         static RefCountPtr<Array<byte> > DecryptString(const String& password, const String& data);
00063         static RefCountPtr<String> EncryptString(const String& password, const Array<byte>& data);
00064         static void EncryptBinary(const String& password, const Array<byte>& data, Array<byte>& output);
00065         static void DecryptBinary(const String& password, Array<byte>& data );
00066 };
00067 
00070 #endif
00071 
00072