Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "QFile"
- #include <unistd.h>
- #include <fstream>
- #include <iostream>
- #include <iomanip>
- #include "modes.h"
- #include "aes.h"
- #include "filters.h"
- int main()
- {
- int buf_flsz;
- int stop = 0;
- QByteArray bt;
- QByteArray data_to_write;
- std::string key = "0123456789abcdef";
- std::string iv = "aaaaaaaaaaaaaaaa";
- QFile fl("/home/nivs/sock");
- fl.open(QIODevice::ReadOnly);
- int size_fl = fl.size();
- std::ofstream outf("/home/nivs/cryptfilm");
- std::string plaintext;
- std::string ciphertext;
- while (stop++ < 30) {
- sleep(1);
- buf_flsz = fl.size();
- if (buf_flsz > size_fl) {
- fl.seek(size_fl);
- size_fl = buf_flsz;
- data_to_write = fl.readAll();
- plaintext = QString(data_to_write.toBase64()).toUtf8().constData();
- CryptoPP::AES::Encryption aesEncryption((byte *)key.c_str(), CryptoPP::AES::DEFAULT_KEYLENGTH);
- CryptoPP::CBC_Mode_ExternalCipher::Encryption cbcEncryption( aesEncryption, (byte *)iv.c_str() );
- CryptoPP::StreamTransformationFilter stfEncryptor(cbcEncryption, new CryptoPP::StringSink( ciphertext ) );
- stfEncryptor.Put( reinterpret_cast<const unsigned char*>( plaintext.c_str() ), plaintext.length() + 1 );
- stfEncryptor.MessageEnd();
- outf << ciphertext;
- }
- }
- fl.close();
- outf.flush();
- outf.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement