Advertisement
nivs

Untitled

Mar 23rd, 2014
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.46 KB | None | 0 0
  1. #include "QFile"
  2. #include <unistd.h>
  3.  
  4. #include <fstream>
  5. #include <iostream>
  6. #include <iomanip>
  7.  
  8. #include "modes.h"
  9. #include "aes.h"
  10. #include "filters.h"
  11.  
  12. int main()
  13. {
  14.     int buf_flsz;
  15.     int stop = 0;
  16.     QByteArray bt;
  17.     QByteArray data_to_write;
  18.  
  19.     std::string key = "0123456789abcdef";
  20.     std::string iv = "aaaaaaaaaaaaaaaa";
  21.  
  22.     QFile fl("/home/nivs/sock");
  23.     fl.open(QIODevice::ReadOnly);
  24.  
  25.     int size_fl = fl.size();
  26.  
  27.     std::ofstream outf("/home/nivs/cryptfilm");
  28.     std::string plaintext;
  29.     std::string ciphertext;
  30.  
  31.     while (stop++ < 30) {
  32.         sleep(1);
  33.         buf_flsz = fl.size();
  34.         if (buf_flsz > size_fl) {
  35.             fl.seek(size_fl);
  36.             size_fl = buf_flsz;
  37.             data_to_write = fl.readAll();
  38.  
  39.             plaintext = QString(data_to_write.toBase64()).toUtf8().constData();
  40.  
  41.             CryptoPP::AES::Encryption aesEncryption((byte *)key.c_str(), CryptoPP::AES::DEFAULT_KEYLENGTH);
  42.             CryptoPP::CBC_Mode_ExternalCipher::Encryption cbcEncryption( aesEncryption, (byte *)iv.c_str() );
  43.  
  44.             CryptoPP::StreamTransformationFilter stfEncryptor(cbcEncryption, new CryptoPP::StringSink( ciphertext ) );
  45.             stfEncryptor.Put( reinterpret_cast<const unsigned char*>( plaintext.c_str() ), plaintext.length() + 1 );
  46.             stfEncryptor.MessageEnd();
  47.  
  48.             outf << ciphertext;
  49.         }
  50.     }
  51.     fl.close();
  52.     outf.flush();
  53.     outf.close();
  54.     return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement