its byte data in char data type !? how i transform it to byte data type ? El viernes, 7 de diciembre de 2012 19:18:31 UTC-3, Alvaro Leiva escribió: > > I have been trying to use the HexDecoder as it shows: > http://www.cryptopp.com/wiki/HexDecoder to decode the key and iv in a > usefull manner to be compatible with: .SetKeyWithIV(), so far I have > tried a bounch of things with no luck, here is my failed implementation: > > *#include "osrng.h" > * > *using CryptoPP::AutoSeededRandomPool;* > * > * > *#include <iostream>* > *using std::cout;* > *using std::cerr;* > *using std::endl;* > * > * > *#include <string>* > *using std::string;* > * > * > *#include <cstdlib>* > *using std::exit;* > * > * > *#include "cryptlib.h"* > *using CryptoPP::Exception;* > * > * > *#include "hex.h"* > *using CryptoPP::HexEncoder;* > *using CryptoPP::HexDecoder;* > * > * > *#include "filters.h"* > *using CryptoPP::StringSink;* > *using CryptoPP::StringSource;* > *using CryptoPP::StreamTransformationFilter;* > * > * > *#include "aes.h"* > *using CryptoPP::AES;* > * > * > *#include "ccm.h"* > *using CryptoPP::CTR_Mode;* > * > * > *#include "assert.h"* > * > * > * > * > *void CharToByte(char* chars, byte* bytes, unsigned int count){* > * for(unsigned int i = 0; i < count; i++)* > * bytes[i] = (byte)chars[i];* > *}* > * > * > *void ByteToChar(byte* bytes, char* chars, unsigned int count){* > * for(unsigned int i = 0; i < count; i++)* > * chars[i] = (char)bytes[i];* > *}* > * > * > * > * > *int main(int argc, char* argv[])* > *{* > * AutoSeededRandomPool prng;* > * > * > * byte key[AES::DEFAULT_KEYLENGTH];* > * prng.GenerateBlock(key, sizeof(key));* > * > * > * byte iv[AES::BLOCKSIZE];* > * prng.GenerateBlock(iv, sizeof(iv));* > * > * > * string plain = "CTR Mode Test";* > * string cipher, encoded, recovered, skey, siv, fkey, fiv;* > * /*********************************\* > * \*********************************/* > * > * > * // Pretty print key* > * encoded.clear();* > * StringSource(key, sizeof(key), true,* > * new HexEncoder(* > * new StringSink(skey)* > * ) // HexEncoder* > * ); // StringSource* > * cout << "key: " << skey << endl;* > * > * > * // Pretty print iv* > * encoded.clear();* > * StringSource(iv, sizeof(iv), true,* > * new HexEncoder(* > * new StringSink(siv)* > * ) // HexEncoder* > * ); // StringSource* > * cout << "iv: " << siv << endl;* > * > * > * /*********************************\* > * \*********************************/* > * > * > * > * > * > * > * StringSource ss1(skey, true /*pumpAll*/,* > * new HexDecoder(* > * new StringSink(fkey)* > * ) // HexDecoder* > * ); // StringSource* > * > * > * StringSource ss2(siv, true /*pumpAll*/,* > * new HexDecoder(* > * new StringSink(fiv)* > * ) // HexDecoder* > * ); // StringSource* > * > * > * > * > * > * > * try* > * {* > * > * > * > * > * > * > * > * > * > * > * cout << "plain text: " << plain << endl;* > * > * > * CTR_Mode< AES >::Encryption e;* > * e.SetKeyWithIV(fkey.data(), fkey.size(), fiv.data());* > * > * > * // The StreamTransformationFilter adds padding* > * // as required. ECB and CBC Mode must be padded* > * // to the block size of the cipher.* > * StringSource(plain, true, * > * new StreamTransformationFilter(e,* > * new StringSink(cipher)* > * ) // StreamTransformationFilter * > * ); // StringSource* > * }* > * catch(const CryptoPP::Exception& e)* > * {* > * cerr << e.what() << endl;* > * exit(1);* > * }* > * > * > * /*********************************\* > * \*********************************/* > * > * > * // Pretty print* > * encoded.clear();* > * StringSource(cipher, true,* > * new HexEncoder(* > * new StringSink(encoded)* > * ) // HexEncoder* > * ); // StringSource* > * cout << "cipher text: " << encoded << endl;* > * > * > * /*********************************\* > * \*********************************/* > * > * > * try* > * {* > * CTR_Mode< AES >::Decryption d;* > * d.SetKeyWithIV(key, sizeof(key), iv);* > * > * > * // The StreamTransformationFilter removes* > * // padding as required.* > * StringSource s(cipher, true, * > * new StreamTransformationFilter(d,* > * new StringSink(recovered)* > * ) // StreamTransformationFilter* > * ); // StringSource* > * > * > * cout << "recovered text: " << recovered << endl;* > * }* > * catch(const CryptoPP::Exception& e)* > * {* > * cerr << e.what() << endl;* > * exit(1);* > * }* > * > * > * /*********************************\* > * \*********************************/* > * > * > * return 0;* > *}* > > > the g++ compiler returns: > > Driver.cpp: In function ‘int main(int, char**)’: > Driver.cpp:112: error: invalid conversion from ‘const char*’ to ‘const > byte*’ > Driver.cpp:112: error: initializing argument 1 of ‘void > CryptoPP::SimpleKeyingInterface::SetKeyWithIV(const byte*, size_t, const > byte*)’ > Driver.cpp:112: error: invalid conversion from ‘const char*’ to ‘const > byte*’ > Driver.cpp:112: error: initializing argument 3 of ‘void > CryptoPP::SimpleKeyingInterface::SetKeyWithIV(const byte*, size_t, const > byte*)’ > > thank u 4 your time !!! >
-- 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.
