示例#1
2
std::string to_string(Hash const& hash)
{
    CryptoPP::HexEncoder enc;
    enc.Put(reinterpret_cast<byte const*>(hash.digest.data()), hash.digest.size());
    std::array<char, 2*std::tuple_size<decltype(hash.digest)>::value + 1> buffer;
    auto const res = enc.Get(reinterpret_cast<byte*>(buffer.data()), 2*hash.digest.size());
    GHULBUS_ASSERT(res == 2*hash.digest.size());
    buffer.back() = '\0';
    return std::string(begin(buffer), end(buffer));
}
示例#2
1
文件: main.cpp 项目: 158906/inz
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; 
}
示例#3
1
int s3fs_keyform(byte* outkey, string inkey)
{
  CryptoPP::HexEncoder encoder;
  encoder.Put((byte*)inkey.c_str(), inkey.length());
  encoder.MessageEnd();
  encoder.Get(outkey, CryptoPP::AES::DEFAULT_KEYLENGTH);
  return 0; 
}
// --------------------------------------------------------------------------
document::document () :
 node(std::shared_ptr<document>(this, [](document*){})),
 m_implementation(m_document)
// --------------------------------------------------------------------------
{
  m_html = false;
  m_mode = no_quirks_mode;
  m_content_type = "application/xml";
  m_encoding = "utf-8";
  m_url = "about:blank";

  if (global_object)
  {
    m_origin = global_object->m_document->m_origin;
    m_script_origin = global_object->m_document->m_script_origin;
  }
  else
  {
    // Default is a globally unique identifier.
    // We'll just generate 32 random bytes as the ID.
    
    CryptoPP::AutoSeededRandomPool rng;
    CryptoPP::HexEncoder enc;
    byte bin[32];
    char hex[64];

    rng.GenerateBlock(bin, 32);
    enc.PutMessageEnd(bin, 32);
    enc.Get(reinterpret_cast<byte*>(hex), 64);
    
    m_origin = hex;
    m_script_origin = m_origin;
  }
}
示例#5
0
fs::path http_cache::cache_file (const std::string& url) const
{
    std::array<uint8_t, 32> digest;
    CryptoPP::SHA().CalculateDigest(digest.data(),
                                    reinterpret_cast<const uint8_t*>(&url[0]),
                                    url.size());
    CryptoPP::HexEncoder hex;
    hex.Put(digest.data(), digest.size());
    std::string hexstr;
    hexstr.resize(64);
    hex.Get(reinterpret_cast<uint8_t*>(&hexstr[0]), 64);
    return dir_ / hexstr;
}
示例#6
0
文件: main.cpp 项目: 158906/inz
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);
}
示例#7
0
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);
}
示例#8
0
        //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;
        }
示例#9
0
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;
}
示例#10
0
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;
}
示例#11
0
 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;
 }
示例#12
0
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;
}
示例#13
0
/*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;
}
示例#14
0
// 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;
}
示例#15
0
文件: main.cpp 项目: 158906/inz
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);
}
示例#16
0
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();
}
void encodeHex(const  byte * inString1, byte * inString2,const size_t length){
  CryptoPP::HexEncoder hexEncoder;
  hexEncoder.Put(inString1,length);
  hexEncoder.MessageEnd();
  hexEncoder.Get(inString2,length*2);
}
示例#18
-1
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);
}