void crypt(string message, int &i, int &output_int_resztaDziel){ CryptoPP::SHA3_512 hash; byte digest[ CryptoPP::SHA512::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::string output_bin; output_bin = GetBinaryStringFromHexString(output); std::string output_bin_wynikDziel; std::string output_bin_resztaDziel; output_bin_wynikDziel = output_bin.substr(0, output_bin.length()-6); //na sztywno dla m=64 output_bin_resztaDziel = output_bin.substr(output_bin.length()-6, 6);//m = 64 output_int_resztaDziel = GetIntegerFromBinaryString(output_bin_resztaDziel); char * rho; const char *coutput_bin = output_bin_wynikDziel.c_str(); rho = strchr(coutput_bin,'1'); i = rho-coutput_bin; }
void crypt(string message, int &i, int &output_int_resztaDziel){ //int crypt(std::string message) { CryptoPP::SHA3_512 hash; byte digest[ CryptoPP::SHA512::DIGESTSIZE ]; hash.CalculateDigest( digest, (byte*)message.c_str(), message.length() ); //std::cout << digest << std::endl; //digest zawiera hasha message CryptoPP::HexEncoder encoder;// //CryptoPP::BaseN_Encoder encoder; std::string output; encoder.Attach( new CryptoPP::StringSink( output ) ); encoder.Put( digest, sizeof(digest) ); encoder.MessageEnd(); std::string output_bin; output_bin = GetBinaryStringFromHexString(output); std::string output_bin_wynikDziel; std::string output_bin_resztaDziel; //int output_int_resztaDziel; output_bin_wynikDziel = output_bin.substr(0, output_bin.length()-6); //na sztywno dla m=64 output_bin_resztaDziel = output_bin.substr(output_bin.length()-6, 6);//m = 64 output_int_resztaDziel = GetIntegerFromBinaryString(output_bin_resztaDziel); //std::cout << output << std::endl; //std::cout << output.length() << std::endl; //std::cout << output_bin << std::endl; //std::cout << output_bin_wynikDziel << std::endl; //std::cout << output_bin_resztaDziel << std::endl; //std::cout << output_int_resztaDziel << std::endl; //std::cout << output_bin.length() << std::endl; //std::cout << "" << std::endl; // char str11[] = "000100010011111"; char * rho; const char *coutput_bin = output_bin_wynikDziel.c_str(); rho = strchr(coutput_bin,'1');//zwraca wskaŸnik do pierwszego wyst¹pienia 1 //std::cout << rho-coutput_bin+1 <<std::endl; i = rho-coutput_bin; /////////////UWAGA : BY£O + 1!!! //return i; //return std::string((char*)digest); }
std::string SHA512(std::string data) { byte const* pbData = (byte*) data.data(); unsigned int nDataLen = data.size(); byte abDigest[CryptoPP::SHA512::DIGESTSIZE]; CryptoPP::SHA512().CalculateDigest(abDigest, pbData, nDataLen); CryptoPP::HexEncoder encoder; std::string output; encoder.Attach( new CryptoPP::StringSink( output ) ); encoder.Put( abDigest, sizeof(abDigest) ); encoder.MessageEnd(); return output; }
std::string get_sha2_from_string(const std::string& rhs) { // byte = typedef for unsigned char byte hashBytes[CryptoPP::SHA256::DIGESTSIZE] = {0}; CryptoPP::SHA256().CalculateDigest( hashBytes, reinterpret_cast<const byte*>(rhs.c_str()), rhs.length()); CryptoPP::HexEncoder encoder; std::string hash; encoder.Attach(new CryptoPP::StringSink(hash)); encoder.Put(hashBytes, sizeof(hashBytes)); encoder.MessageEnd(); return hash; }
std::string makeHash(const std::string& input) { CryptoPP::SHA512 hash; byte digest[ CryptoPP::SHA512::DIGESTSIZE ]; hash.CalculateDigest( digest, (byte*) input.c_str(), input.length() ); CryptoPP::HexEncoder encoder; std::string output; encoder.Attach( new CryptoPP::StringSink( output ) ); encoder.Put( digest, sizeof(digest) ); encoder.MessageEnd(); return output; }
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); }
//Hash data by MD5 algorhitm inline std::string MD5(const std::string& data) { std::string res; CryptoPP::MD5 hash; byte digest[CryptoPP::MD5::DIGESTSIZE]; hash.CalculateDigest(digest, (byte*)data.c_str(), data.size()); CryptoPP::HexEncoder encoder; encoder.Attach(new CryptoPP::StringSink(res)); encoder.Put(digest, sizeof(digest)); encoder.MessageEnd(); return res; }
string hashdomain(string request) { CryptoPP::SHA hashfun; CryptoPP::HexEncoder encoder; std::string output; byte digest[CryptoPP::SHA::DIGESTSIZE]; hashfun.CalculateDigest(digest, (byte*) request.c_str(), request.length()); encoder.Attach(new CryptoPP::StringSink(output)); encoder.Put(digest, sizeof(digest)); encoder.MessageEnd(); return output; }
/*Calculate SHA1 hash*/ string HashCalculate(string input_string) { CryptoPP::SHA1 hash; byte digest[CryptoPP::SHA1::DIGESTSIZE]; string output; //calculate hash hash.CalculateDigest(digest, (const byte *)input_string.c_str(), input_string.size()); //encode in Hex CryptoPP::HexEncoder encoder; CryptoPP::StringSink *SS = new CryptoPP::StringSink(output); encoder.Attach(SS); encoder.Put(digest, sizeof(digest)); encoder.MessageEnd(); //prepend 0x output = "0x" + output; 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; }
int crypt(std::string message) { CryptoPP::SHA3_256 hash; byte digest[ CryptoPP::SHA::DIGESTSIZE ]; hash.CalculateDigest( digest, (byte*)message.c_str(), message.length() ); //std::cout << digest << std::endl; //digest zawiera hasha message CryptoPP::HexEncoder encoder;// //CryptoPP::BaseN_Encoder encoder; std::string output; encoder.Attach( new CryptoPP::StringSink( output ) ); encoder.Put( digest, sizeof(digest) ); encoder.MessageEnd(); std::string output_bin; output_bin = GetBinaryStringFromHexString(output); //std::cout << output << std::endl; //std::cout << output.length() << std::endl; //std::cout << output_bin << std::endl; //std::cout << output_bin.length() << std::endl; //std::cout << "" << std::endl; // char str11[] = "000100010011111"; char * rho; const char *coutput_bin = output_bin.c_str(); rho = strchr(coutput_bin,'1'); //std::cout << rho-coutput_bin+1 <<std::endl; int i = rho-coutput_bin+1; return i; //return std::string((char*)digest); }
void CLoginDlg::OnBnClickedOk() { // TODO: 여기에 컨트롤 알림 처리기 코드를 추가합니다. CComm func; //환경파일 저장되는지 확인. CString plainTxt; m_cID.GetWindowText(m_strID); m_cPwd.GetWindowText(plainTxt); #ifdef _HTTPS CryptoPP::MD5 hash; byte digest[CryptoPP::MD5::DIGESTSIZE]; std::string message = func.Convert2string(plainTxt); 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::cout << output << std::endl; m_strPWD = output.c_str(); m_strPWD.MakeLower(); //OutputDebugString(m_strPWD); #else m_strPWD = plainTxt; #endif CString strFormData = L""; strFormData.Format(_T("email=%s&password=%s"), m_strID, m_strPWD); //로그인 DWORD dwRtn = login(SRV_URL, LGN_API, strFormData); if (dwRtn == HTTP_STATUS_FORBIDDEN){ MessageBox(L"ID or Password Error!"); m_cID.SetWindowText(L""); m_cPwd.SetWindowText(L""); m_cID.SetFocus(); return; }else if (dwRtn == HTTP_STATUS_DENIED){ //토큰 Expire AfxMessageBox(L"Token Expire or Not found!"); return; } else if (dwRtn != HTTP_STATUS_OK){ MessageBox(L"Login Fail"); m_cID.SetWindowText(L""); m_cPwd.SetWindowText(L""); m_cID.SetFocus(); return; } //사용자 프로파일 취득. // 성공일 경우 사용자 프로파일 취득. dwRtn = userProfile(SRV_URL, PROFILE); if (dwRtn != HTTP_STATUS_OK){ AfxMessageBox(L"Get User Profile Fail"); return; } CDialogEx::OnOK(); }
std::string transformToSHA256(std::string plainText, bool upperCase) { // Crypto++ SHA256 object CryptoPP::SHA256 hash; // Use native byte instead of casting chars byte digest[CryptoPP::SHA256::DIGESTSIZE]; // Do the actual calculation, require a byte value so we need a cast hash.CalculateDigest(digest, (const byte*)plainText.c_str(), plainText.length()); // Crypto++ HexEncoder object CryptoPP::HexEncoder encoder; // Our output std::string output; // Drop internal hex encoder and use this, returns uppercase by default encoder.Attach(new CryptoPP::StringSink(output)); encoder.Put(digest, sizeof(digest)); encoder.MessageEnd(); // Make sure we want uppercase if(upperCase) return output; // Convert to lowercase if needed return asLowerCaseString(output); }