I used this to test it and it will not encrypt or decrypt correctly.
it encrypts but it won't decrypt
i used this command while testing
cat ./testi.txt | ./testencryption test true | ./testencryption test
false
//
============================================================================
// Name : testencryption.cpp
// Author : kehon
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C, Ansi-style
//
============================================================================
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string>
#include <boost/iostreams/device/file_descriptor.hpp>
#include <boost/iostreams/stream.hpp>
#include <cryptopp/modes.h>
#include <cryptopp/files.h>
#include <cryptopp/aes.h>
#include <cryptopp/secblock.h>
#include <cryptopp/sha.h>
#include <cryptopp/osrng.h>
#include <cryptopp/hex.h>
#include <cryptopp/channels.h>
using namespace std;
using namespace boost;
using namespace boost::iostreams;
using namespace CryptoPP;
int main(int argc, char * argv[])
{
//argv[0] pass (true|false)encdecrypt
if(argc < 3)
{
cout << "usage: " << argv[0] << "pass (true|false)enc|decrypt";
exit(1);
}
AutoSeededRandomPool rng;
//string iv_str =
"1234567891011121314151617181920212223242526272829303132";
SecByteBlock pass(SHA512::DIGESTSIZE);
SHA512().CalculateDigest(pass,(byte *)argv[1],strlen(argv[1]));
FILE * infile = stdin, * outfile = stdout;
// infile = fopen("testi.txt","r");
// outfile = fopen("testo.txt","w");
int ifd = fileno(infile);
file_descriptor_source ifdsink(ifd);
stream<file_descriptor_source> ifstm(ifdsink);
istream & in = ifstm;
int ofd = fileno(outfile);
file_descriptor_sink ofdsink(ofd);
stream<file_descriptor_sink > ofstm(ofdsink);
ostream & out = ofstm;
// ChannelSwitch();
// exit(0);
if(strcasecmp(argv[2],"true") == 0)
{
// string str1 = "line1\n";
// string str2 = "line2";
// FileSink osink("testf.txt");
// StringSource(str1,true,new
Redirector(osink,Redirector::DATA_ONLY));
// StringSource(str2,true,new Redirector(osink));
// exit(0);
cerr << "encrypting\n";
SecByteBlock iv(AES::BLOCKSIZE);
rng.GenerateBlock(iv,iv.size());
FileSink sink(out);
ArraySource(iv,iv.size(),true, new
Redirector(sink,Redirector::DATA_ONLY));
SecByteBlock buf(SHA1::DIGESTSIZE);
SHA1().CalculateDigest(buf,iv,iv.size());
string hash;
ArraySource(buf,buf.size(),true,new HexEncoder(new
StringSink(hash)));
cerr << "encrypt: iv sha1 = " << hash << endl;
AESEncryption aese((byte *)pass.data(),AES::MAX_KEYLENGTH);
CFB_Mode_ExternalCipher::Encryption encryptor(aese,iv);
// OFB_Mode<AES>::Encryption encryptor((byte
*)pass.data(),AES::MAX_KEYLENGTH,iv);
FileSource(in,true,
new StreamTransformationFilter(
encryptor,
new Redirector(sink)));
cerr << "done\n";
}
else
{
// string str1 = "line1\n";
// string str2 = "line2";
// SecByteBlock rstr1(str1.size()), rstr2(str2.size()); /**
recovered
*/
// ArraySink sink1(rstr1,rstr1.size());
// ArraySink sink2(rstr2,rstr2.size());
//// ChannelSwitch cswitch;
//// cswitch.AddDefaultRoute();
// FileSource src("testf.txt",false,new Redirector(sink1));
// src.Pump(rstr1.size());
// src.Detach(new Redirector(sink2));
// src.Pump(rstr2.size());
//
//
// cout << "recovered : '" << string((char *)rstr1.BytePtr()) << "'
'" << string((char *)rstr2.BytePtr()) << "'\n";
//
// exit(0);
cerr << "decrypting\n";
SecByteBlock iv(AES::BLOCKSIZE);
FileSource source(in,false,new ArraySink(iv,iv.size()));
source.Pump(iv.size());
SecByteBlock buf(SHA1::DIGESTSIZE);
SHA1().CalculateDigest(buf,iv,iv.size());
string hash;
ArraySource(buf,buf.size(),true,new HexEncoder(new
StringSink(hash)));
cerr << "decrypt: iv sha1 = " << hash << endl;
AESDecryption aesd((byte *)pass.data(),AES::MAX_KEYLENGTH);
CFB_Mode_ExternalCipher::Decryption decrypter(aesd,iv);
// OFB_Mode<AES>::Decryption decrypter((byte
*)pass.data(),AES::MAX_KEYLENGTH,iv);
source.Attach(
new StreamTransformationFilter(
decrypter,
new FileSink(out)));
source.PumpAll();
cerr << "done\n";
}
return EXIT_SUCCESS;
}
--
You received this message because you are subscribed to the "Crypto++ Users"
Google Group.
To unsubscribe, send an email to [email protected].
More information about Crypto++ and this group is available at
http://www.cryptopp.com.