Beispiel #1
0
void testEncryption()
{
    std::string plain_text = "The rooster crows at midnight!";
    std::string key = "A16ByteKey......";

    DataPtr iv = Data::create("IV6ByteKey......");
    Data::ByteArr& iv_raw = iv->getRawData();

    //iv_raw.resize(Protect::IV_SIZE, 0);

    DataPtr enc = Protect::encodeIV(Data::create(plain_text),
                                    Data::create(key),
                                    iv);
    DataPtr enc2 = Protect::encode(Data::create(plain_text),
                                   Data::create(key));

    log("Enc: "+Base64::encode(enc)->toString());
    log("Enc2: "+Base64::encode(enc2)->toString());

    DataPtr dec = Protect::decodeIV(enc, Data::create(key), iv);
    DataPtr dec2 = Protect::decode(enc2, Data::create(key));
    log("Dec: "+dec->toString());
    log("Dec2: "+dec2->toString());


}
Beispiel #2
0
void testData()
{

    DataPtr dun = Data::create("hello-worldhello-worldhello-worldhello-worldhello-worldhello-worldhello-worldhello-worldhello-worldhello-worldhello-worldhello-world");
    log(dun->toString());

    DataPtr d = ZLib::compress(dun);


    DataPtr base64 = Base64::encode(d);
    if(base64)
    {
        log(base64->toString());

        DataPtr dec = Base64::decode(base64);
        log(ZLib::decompress(dec)->toString());
        std::string dec_string = base64->toString();

        if(dec)
            log(dec_string);

        dec_string[2] = '*';

        DataPtr dec2 = Base64::decode(Data::create(dec_string));
        if(dec2)
            log("Dec ok");
        else
            log("Dec failed");

    }

}