Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #include "ibrcommon/ssl/XORStream.h"
00009
00010 namespace ibrcommon
00011 {
00012 XORStream::XORStream(std::ostream &stream, const CipherMode mode, std::string key)
00013 : CipherStream(stream, mode), _key(key)
00014 {
00015 }
00016
00017 XORStream::~XORStream()
00018 {
00019 }
00020
00021 void XORStream::encrypt(char *buf, const size_t size)
00022 {
00023 const char *keydata = _key.c_str();
00024 const size_t keylength = _key.length();
00025
00026 for (size_t i = 0; i < size; i++)
00027 {
00028 buf[i] = buf[i] ^ keydata[i % keylength];
00029 }
00030 }
00031
00032 void XORStream::decrypt(char *buf, const size_t size)
00033 {
00034 const char *keydata = _key.c_str();
00035 const size_t keylength = _key.length();
00036
00037 for (size_t i = 0; i < size; i++)
00038 {
00039 buf[i] = buf[i] ^ keydata[i % keylength];
00040 }
00041 }
00042 }