void Md5Adapter::CalculateDigest(std::vector<unsigned char> data, std::vector<unsigned char> & digest) { CryptoPP::Weak1::MD5 hash; digest.assign(CryptoPP::Weak1::MD5::DIGESTSIZE, 0); hash.CalculateDigest(&digest[0], &data[0], data.size()); }
std::string MD5encode::encode(std::string const &message) { CryptoPP::Weak1::MD5 hash; byte digest[ CryptoPP::Weak1::MD5::DIGESTSIZE ]; hash.CalculateDigest( digest, (byte*) message.c_str(), message.length() ); CryptoPP::HexEncoder encoder; std::string output; encoder.Attach( new CryptoPP::StringSink( output ) ); encoder.Put( digest, sizeof(digest) ); encoder.MessageEnd(); std::transform(output.begin(), output.end(), output.begin(), ::tolower); return (output); }
// Login subscriber bool filmonAPIlogin(std::string username, std::string password) { bool res = filmonAPIgetSessionKey(); if (res) { std::cerr << "FilmonAPI: logging in user" << std::endl; filmonUsername = username; filmonpassword = password; // Password is MD5 hex CryptoPP::Weak1::MD5 hash; byte digest[CryptoPP::Weak1::MD5::DIGESTSIZE]; hash.CalculateDigest(digest, (byte*) password.c_str(), password.length()); CryptoPP::HexEncoder encoder; std::string md5pwd; encoder.Attach(new CryptoPP::StringSink(md5pwd)); encoder.Put(digest, sizeof(digest)); encoder.MessageEnd(); toLowerCase(md5pwd); std::string params = "login="******"&password="******"tv/api/login", sessionKeyParam + "&" + params); if (res) { Json::Value root; Json::Reader reader; reader.parse(&response.memory[0], &response.memory[(long) response.size - 1], root); // Favorite channels channelList.clear(); Json::Value favouriteChannels = root["favorite-channels"]; unsigned int channelCount = favouriteChannels.size(); for (unsigned int channel = 0; channel < channelCount; channel++) { Json::Value chId = favouriteChannels[channel]["channel"]["id"]; channelList.push_back(chId.asUInt()); std::cerr << "FilmonAPI: added channel " << chId.asUInt() << std::endl; } clearResponse(); } } return res; }