Esempio n. 1
0
KeyStorage::DecodeKey KeyStorage::getWifiDecodeKey(
        const std::string& ssid,
        const std::string& bssid)
{
    DecodeKey result;

    static Data salt1("MCeGNFxMgyswwJfn6zCf");
    static Data salt2("MfcLVmEF95tF6Sa6627e");
    static Data salt3("5aU3a9EmyuwyyTRss7wM");

    DataPtr res = Data::create(salt1);
    res += ssid;
    res += salt2;
    res += bssid;
    res += salt3;

    DataPtr hash = Hash::apply(res);
    if(hash)
    {
        Data::ByteArr& raw = hash->getRawData();
        if(raw.size() >= Protect::KEY_SIZE + Protect::IV_SIZE)
        {
            DataPtr key = Data::create(&raw[0], Protect::KEY_SIZE);
            DataPtr iv = Data::create(&raw[0]+Protect::KEY_SIZE, Protect::IV_SIZE);

            result.key = key;
            result.iv = iv;
        }
    }

    return result;
}
Esempio n. 2
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());


}