Example #1
0
int main(int argv, char** argc)
{
    std::fstream fs1(argc[1], std::ios::in | std::ios::binary);

    CryptoPP::SHA256 hash;

    if (argv > 1){
        if (fs1.is_open())
        {

            size_t block_size = 0;
            byte digest[CryptoPP::SHA256::DIGESTSIZE];
            fs1.seekg(0, fs1.end);
            int digest_size = 0;
            int pos = fs1.tellg();
            while(pos > 0){

                block_size = (pos - 1) % BLOCK_SIZE + 1;
                pos -= block_size;
                fs1.seekg(pos);

                byte buf[block_size + digest_size];\
                fs1.read(reinterpret_cast<char*>(buf), block_size);

                for (int i = 0; i <  digest_size; i++)
                    buf[block_size + i] = digest[i];

                hash.CalculateDigest(digest, buf, block_size+digest_size);

                digest_size = CryptoPP::SHA256::DIGESTSIZE;
            }

            for (int i = 0; i < CryptoPP::SHA256::DIGESTSIZE; i++)
                std::cout << std::hex << (int)digest[i] << std::dec;
            std::cout << std::endl;
        }
        else
        {
            std::cout << "cannot open file " << argc[1];
        }
    }else{
        byte digest[CryptoPP::SHA256::DIGESTSIZE];
        byte test[2] = {1, 1};
        hash.CalculateDigest(digest, test, 2);
        for (int i = 0; i < CryptoPP::SHA256::DIGESTSIZE; i++)
            std::cout << std::hex << (int)digest[i] << std::dec;
    }
    std::cout << std::endl;
    return 0;
}
Example #2
0
bool CryptoECDSA::VerifyData(SecureBinaryData const & binMessage, 
                             SecureBinaryData const & binSignature,
                             BTC_PUBKEY const & cppPubKey)
                            
{


   static CryptoPP::SHA256  sha256;
   static CryptoPP::AutoSeededRandomPool prng;

   assert(cppPubKey.Validate(prng, 3));

   // We execute the first SHA256 op, here.  Next one is done by Verifier
   SecureBinaryData hashVal(32);
   sha256.CalculateDigest(hashVal.getPtr(), 
                          binMessage.getPtr(), 
                          binMessage.getSize());

   // Verifying message 
   BTC_VERIFIER verifier(cppPubKey); 
   return verifier.VerifyMessage((const byte*)hashVal.getPtr(), 
                                              hashVal.getSize(),
                                 (const byte*)binSignature.getPtr(), 
                                              binSignature.getSize());
}
Example #3
0
TEST(AccountTest, TestAccountAuthorized)
{
    if (settings::instance().cassandraSeeds.size() == 0) return;
    
    const char* const USERNAME = "******";
    const char* const PASSWORD = "******";
    
    user_account::create(USERNAME, PASSWORD, 1);
    
    
    unsigned char hashResult[CryptoPP::SHA256::DIGESTSIZE];
    CryptoPP::SHA256 sha;
    sha.CalculateDigest(&hashResult[0], (unsigned char*)USERNAME, strlen(USERNAME));
    
    std::string nameHash = util::hex_encode(hashResult, CryptoPP::SHA256::DIGESTSIZE);
    
    sha.Restart();
    sha.CalculateDigest(&hashResult[0], (unsigned char*)PASSWORD, strlen(PASSWORD));
    
    std::string pwHash = util::hex_encode(hashResult, CryptoPP::SHA256::DIGESTSIZE);
    
    std::mutex m;
    std::condition_variable cv;
    
    auto challengeBytes = util::random_bytes(1024);
    auto pwHashAndChallenge = pwHash + challengeBytes;
    
    sha.Restart();
    sha.CalculateDigest(&hashResult[0], (unsigned char*)pwHashAndChallenge.c_str(), pwHashAndChallenge.length());
    
    auto challengeResponse = util::hex_encode(hashResult, CryptoPP::SHA256::DIGESTSIZE);
    
    bool uauthd = false;
    bool returned = false;
    
    user_account::is_authorized(nameHash, challengeBytes, challengeResponse, [&] (bool authd) {
        std::lock_guard<std::mutex> lk(m);
        returned = true;
        uauthd = authd;
        cv.notify_one();
    });
    
    std::unique_lock<std::mutex> lk(m);
    cv.wait(lk, [&] {return returned == true;});
    
    ASSERT_EQ(true, uauthd);
}
Example #4
0
TEST(AccountTest, TestCreateAccount)
{
    if (settings::instance().cassandraSeeds.size() == 0) return;
    
    const char* const USERNAME = "******";
    const char* const PASSWORD = "******";
    
    user_account::create(USERNAME, PASSWORD, 1);
    
    
    unsigned char hashResult[CryptoPP::SHA256::DIGESTSIZE];
    CryptoPP::SHA256 sha;
    sha.CalculateDigest(&hashResult[0], (unsigned char*)USERNAME, strlen(USERNAME));
    
    std::string nameHash = util::hex_encode(hashResult, CryptoPP::SHA256::DIGESTSIZE);
    
    std::mutex m;
    std::condition_variable cv;
    
    user_account foundAcct;
    bool returned = false;
    bool ufound = false;
    
    user_account::find(nameHash, [&] (bool found, user_account acct) {
        std::lock_guard<std::mutex> lk(m);
        ufound = found;
        returned = true;
        foundAcct = acct;
        cv.notify_one();
    });
    
    std::unique_lock<std::mutex> lk(m);
    cv.wait(lk, [&] {return returned == true;});
    
    ASSERT_EQ(true, ufound);
    ASSERT_EQ(1, foundAcct.user_level());
    ASSERT_EQ(USERNAME, foundAcct.username());
}
Example #5
0
SecureBinaryData CryptoECDSA::SignData(SecureBinaryData const & binToSign, 
                                       BTC_PRIVKEY const & cppPrivKey)
{

   // We trick the Crypto++ ECDSA module by passing it a single-hashed
   // message, it will do the second hash before it signs it.  This is 
   // exactly what we need.
   static CryptoPP::SHA256  sha256;
   static BTC_PRNG prng;

   // Execute the first sha256 op -- the signer will do the other one
   SecureBinaryData hashVal(32);
   sha256.CalculateDigest(hashVal.getPtr(), 
                          binToSign.getPtr(), 
                          binToSign.getSize());

   string signature;
   BTC_SIGNER signer(cppPrivKey);
   CryptoPP::StringSource(
               hashVal.toBinStr(), true, new CryptoPP::SignerFilter(
               prng, signer, new CryptoPP::StringSink(signature))); 
  
   return SecureBinaryData(signature);
}
Example #6
0
void CPropChkSum::OnOK() 
{
	UpdateData();

	CPropertyPage::OnOK();
	if(m_szFileName == _T("")) {
		AfxMessageBox(_T("Please select the file."));
		return ;
	}

	HANDLE hFile = CreateFile(m_szFileName, GENERIC_WRITE | GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,NULL);
	if (hFile == INVALID_HANDLE_VALUE){
		CString str = m_szFileName + _T(" doesn't exist!");
		AfxMessageBox(str);
		return ;
	}

	DWORD dwFileSize = GetFileSize(hFile, NULL);
	HANDLE hFileMap = CreateFileMapping(
						hFile, // 如果这值为INVALID_HANDLE_VALUE,是合法的,上步一定测试啊
						NULL,    // 默认安全性
						PAGE_READWRITE,    // 可读
						0, // 2个32位数示1个64位数,最大文件字节数,
						 // 高字节,文件大小小于4G时,高字节永远为0
						0,//dwFileSize, // 此为低字节,也就是最主要的参数,如果为0,取文件真实大小
						NULL);
	if (hFileMap == NULL)
	{
		CString str = _T("Mapping ") + m_szFileName + _T(" failed!");
		AfxMessageBox(str);
		CloseHandle(hFile);
		return ;
	}

	PVOID pvFile = MapViewOfFile( //pvFile就是得到的指针,用它来直接操作文件
						hFileMap, 
						FILE_MAP_WRITE,     // 可读
						0,      // 文件指针头位置 高字节
						0, // 文件指针头位置 低字节 必为分配粒度的整倍数,windows的粒度为64K
						0);    // 要映射的文件尾,如果为0,则从指针头到真实文件尾
	if (pvFile == NULL)	{
		CString str = _T("MapViewOfFile ") + m_szFileName + _T(" failed, ERROR:!");
		str.Format(_T("MapViewOfFile %s failed, ERROR:%d!"), m_szFileName, GetLastError());
		AfxMessageBox(str);
		CloseHandle(hFileMap);
		CloseHandle(hFile);
		return ;
	}
	// 步骤4: 像操作内存一样操作文件,演示功能把整个文件倒序
	char *pData = (char*)pvFile;

	boost::crc_16_type crc16t;
	crc16t.process_bytes(pData, dwFileSize);
	unsigned short crc16 = crc16t.checksum();
	m_strCRC16.Format(_T("%04X"), crc16);

	boost::crc_ccitt_type crc_ccitt;
	crc_ccitt.process_bytes(pData, dwFileSize);
	crc16 = crc_ccitt.checksum();
	m_strCRC_CCITT.Format(_T("%04X"), crc16);

	boost::crc_xmodem_type  crc_xmdm;
	crc_xmdm.process_bytes(pData, dwFileSize);
	crc16 = crc_xmdm.checksum();
	m_strCRC32C.Format(_T("%04X"), crc16);

	boost::crc_32_type crc32t;
	crc32t.process_bytes(pData, dwFileSize);
	unsigned long crc32 = crc32t.checksum();
	m_strCRC32.Format(_T("%04X"), crc32);

	enum {
		MessageDigest_MD5 = 0,
		MessageDigest_SHA,
		MessageDigest_SHA1,
		MessageDigest_SHA224,
		MessageDigest_SHA256,
		MessageDigest_SHA384,
		MessageDigest_SHA3_224,
		MessageDigest_SHA3_256,
		MessageDigest_SHA3_384,
		MessageDigest_SHA3_512
	};
	
	CString strMessageDigest;
	unsigned char sha_md[120] = {0};
	int index = 0;

	if(m_mdList.GetCheck(MessageDigest_MD5)) {
		CryptoPP::Weak1::MD5 md5;
		md5.CalculateDigest((byte*)&sha_md, (unsigned char *)pData, dwFileSize);
		strMessageDigest.Format( 
			"MD5: %02X%02X%02X%02X%02X%02X%02X%02X"
			"%02X%02X%02X%02X%02X%02X%02X%02X",
			sha_md[0], sha_md[1], sha_md[2], sha_md[3],sha_md[4], sha_md[5], sha_md[6], sha_md[7], 
			sha_md[8], sha_md[9], sha_md[10], sha_md[11],sha_md[12], sha_md[13], sha_md[14], sha_md[15]
		);
		
		m_mdList.SetItemText(MessageDigest_MD5, 0, strMessageDigest);
	}

	if(m_mdList.GetCheck(MessageDigest_SHA)) {
		CryptoPP::SHA sha;
		sha.CalculateDigest((byte*)&sha_md, (unsigned char *)pData, dwFileSize);
		strMessageDigest.Format( 
			"SHA: %02X%02X%02X%02X%02X%02X%02X%02X"
			"%02X%02X%02X%02X%02X%02X%02X%02X"
			"%02X%02X%02X%02X",
			sha_md[0], sha_md[1], sha_md[2], sha_md[3],sha_md[4], sha_md[5], sha_md[6], sha_md[7], 
			sha_md[8], sha_md[9], sha_md[10], sha_md[11],sha_md[12], sha_md[13], sha_md[14], sha_md[15], 
			sha_md[16], sha_md[17], sha_md[18], sha_md[19]
			);
		m_mdList.SetItemText(MessageDigest_SHA, 0, strMessageDigest);
	}

	if(m_mdList.GetCheck(MessageDigest_SHA1)) {
		CryptoPP::SHA1 sha;
		sha.CalculateDigest((byte*)&sha_md, (unsigned char *)pData, dwFileSize);
		strMessageDigest.Format( 
			"SHA1: %02X%02X%02X%02X%02X%02X%02X%02X"
			"%02X%02X%02X%02X%02X%02X%02X%02X"
			"%02X%02X%02X%02X",
			sha_md[0], sha_md[1], sha_md[2], sha_md[3],sha_md[4], sha_md[5], sha_md[6], sha_md[7], 
			sha_md[8], sha_md[9], sha_md[10], sha_md[11],sha_md[12], sha_md[13], sha_md[14], sha_md[15], 
			sha_md[16], sha_md[17], sha_md[18], sha_md[19]
			);
		m_mdList.SetItemText(MessageDigest_SHA1, 0, strMessageDigest);
	}

	if(m_mdList.GetCheck(MessageDigest_SHA224)) {
		CryptoPP::SHA224 sha;
		sha.CalculateDigest((byte*)&sha_md, (unsigned char *)pData, dwFileSize);
		strMessageDigest.Format( 
			"SHA224: %02X%02X%02X%02X%02X%02X%02X%02X"
			"%02X%02X%02X%02X%02X%02X%02X%02X"
			"%02X%02X%02X%02X%02X%02X%02X%02X"
			"%02X%02X%02X%02X",
			sha_md[0], sha_md[1], sha_md[2], sha_md[3],sha_md[4], sha_md[5], sha_md[6], sha_md[7], 
			sha_md[8], sha_md[9], sha_md[10], sha_md[11],sha_md[12], sha_md[13], sha_md[14], sha_md[15], 
			sha_md[16], sha_md[17], sha_md[18], sha_md[19], sha_md[20], sha_md[21], sha_md[22], sha_md[23],
			sha_md[24], sha_md[25], sha_md[26], sha_md[27]
			);
		m_mdList.SetItemText(MessageDigest_SHA224, 0, strMessageDigest);
	}
	
	if(m_mdList.GetCheck(MessageDigest_SHA256)) {
		CryptoPP::SHA256 sha;
		sha.CalculateDigest((byte*)&sha_md, (unsigned char *)pData, dwFileSize);
		strMessageDigest.Format( 
			"SHA256: %02X%02X%02X%02X%02X%02X%02X%02X"
			"%02X%02X%02X%02X%02X%02X%02X%02X"
			"%02X%02X%02X%02X%02X%02X%02X%02X"
			"%02X%02X%02X%02X%02X%02X%02X%02X",
			sha_md[0], sha_md[1], sha_md[2], sha_md[3],sha_md[4], sha_md[5], sha_md[6], sha_md[7], 
			sha_md[8], sha_md[9], sha_md[10], sha_md[11],sha_md[12], sha_md[13], sha_md[14], sha_md[15], 
			sha_md[16], sha_md[17], sha_md[18], sha_md[19], sha_md[20], sha_md[21], sha_md[22], sha_md[23],
			sha_md[24], sha_md[25], sha_md[26], sha_md[27],sha_md[28], sha_md[29], sha_md[30], sha_md[31]
			);
		m_mdList.SetItemText(MessageDigest_SHA256, 0, strMessageDigest);
	}
	
	if(m_mdList.GetCheck(MessageDigest_SHA384)) {
		CryptoPP::SHA384 sha;
		sha.CalculateDigest((byte*)&sha_md, (unsigned char *)pData, dwFileSize);
		strMessageDigest.Format( 
			"SHA384: %02X%02X%02X%02X%02X%02X%02X%02X"
			"%02X%02X%02X%02X%02X%02X%02X%02X"
			"%02X%02X%02X%02X%02X%02X%02X%02X"
			"%02X%02X%02X%02X%02X%02X%02X%02X"
			"%02X%02X%02X%02X%02X%02X%02X%02X"
			"%02X%02X%02X%02X%02X%02X%02X%02X",
			sha_md[0], sha_md[1], sha_md[2], sha_md[3],sha_md[4], sha_md[5], sha_md[6], sha_md[7], 
			sha_md[8], sha_md[9], sha_md[10], sha_md[11],sha_md[12], sha_md[13], sha_md[14], sha_md[15], 

			sha_md[16], sha_md[17], sha_md[18], sha_md[19], sha_md[20], sha_md[21], sha_md[22], sha_md[23],
			sha_md[24], sha_md[25], sha_md[26], sha_md[27],sha_md[28], sha_md[29], sha_md[30], sha_md[31],
			
			sha_md[32], sha_md[33], sha_md[34], sha_md[35], sha_md[36], sha_md[37], sha_md[38], sha_md[39],
			sha_md[40], sha_md[41], sha_md[42], sha_md[43],sha_md[44], sha_md[45], sha_md[46], sha_md[47]
			);
		m_mdList.SetItemText(MessageDigest_SHA384, 0, strMessageDigest);
	}

	if(m_mdList.GetCheck(MessageDigest_SHA3_224)) {
		CryptoPP::SHA3_224 sha;
		sha.CalculateDigest((byte*)&sha_md, (unsigned char *)pData, dwFileSize);
		strMessageDigest.Format( 
			"SHA3-224: %02X%02X%02X%02X%02X%02X%02X%02X"
			"%02X%02X%02X%02X%02X%02X%02X%02X"
			"%02X%02X%02X%02X%02X%02X%02X%02X"
			"%02X%02X%02X%02X",
			sha_md[0], sha_md[1], sha_md[2], sha_md[3],sha_md[4], sha_md[5], sha_md[6], sha_md[7], 
			sha_md[8], sha_md[9], sha_md[10], sha_md[11],sha_md[12], sha_md[13], sha_md[14], sha_md[15], 

			sha_md[16], sha_md[17], sha_md[18], sha_md[19], sha_md[20], sha_md[21], sha_md[22], sha_md[23],
			sha_md[24], sha_md[25], sha_md[26], sha_md[27]
			);
		m_mdList.SetItemText(MessageDigest_SHA3_224, 0, strMessageDigest);
	}

	if(m_mdList.GetCheck(MessageDigest_SHA3_256)) {
		CryptoPP::SHA3_256 sha;
		sha.CalculateDigest((byte*)&sha_md, (unsigned char *)pData, dwFileSize);
		strMessageDigest.Format( 
			"SHA3-256: %02X%02X%02X%02X%02X%02X%02X%02X"
			"%02X%02X%02X%02X%02X%02X%02X%02X"
			"%02X%02X%02X%02X%02X%02X%02X%02X"
			"%02X%02X%02X%02X%02X%02X%02X%02X",
			sha_md[0], sha_md[1], sha_md[2], sha_md[3],sha_md[4], sha_md[5], sha_md[6], sha_md[7], 
			sha_md[8], sha_md[9], sha_md[10], sha_md[11],sha_md[12], sha_md[13], sha_md[14], sha_md[15], 
			sha_md[16], sha_md[17], sha_md[18], sha_md[19], sha_md[20], sha_md[21], sha_md[22], sha_md[23],
			sha_md[24], sha_md[25], sha_md[26], sha_md[27],sha_md[28], sha_md[29], sha_md[30], sha_md[31]
			);
		m_mdList.SetItemText(MessageDigest_SHA3_256, 0, strMessageDigest);
	}

	if(m_mdList.GetCheck(MessageDigest_SHA3_384)) {
		CryptoPP::SHA3_384 sha;
		sha.CalculateDigest((byte*)&sha_md, (unsigned char *)pData, dwFileSize);
		strMessageDigest.Format( 
			"SHA3-384: %02X%02X%02X%02X%02X%02X%02X%02X"
			"%02X%02X%02X%02X%02X%02X%02X%02X"
			"%02X%02X%02X%02X%02X%02X%02X%02X"
			"%02X%02X%02X%02X%02X%02X%02X%02X"
			"%02X%02X%02X%02X%02X%02X%02X%02X"
			"%02X%02X%02X%02X%02X%02X%02X%02X",
			sha_md[0], sha_md[1], sha_md[2], sha_md[3],sha_md[4], sha_md[5], sha_md[6], sha_md[7], 
			sha_md[8], sha_md[9], sha_md[10], sha_md[11],sha_md[12], sha_md[13], sha_md[14], sha_md[15], 

			sha_md[16], sha_md[17], sha_md[18], sha_md[19], sha_md[20], sha_md[21], sha_md[22], sha_md[23],
			sha_md[24], sha_md[25], sha_md[26], sha_md[27],sha_md[28], sha_md[29], sha_md[30], sha_md[31],
			
			sha_md[32], sha_md[33], sha_md[34], sha_md[35], sha_md[36], sha_md[37], sha_md[38], sha_md[39],
			sha_md[40], sha_md[41], sha_md[42], sha_md[43],sha_md[44], sha_md[45], sha_md[46], sha_md[47]
			);
		m_mdList.SetItemText(MessageDigest_SHA3_384, 0, strMessageDigest);
	}

	if(m_mdList.GetCheck(MessageDigest_SHA3_512)) {
		CryptoPP::SHA3_512 sha;
		sha.CalculateDigest((byte*)&sha_md, (unsigned char *)pData, dwFileSize);
		strMessageDigest.Format( 
			"SHA3-512: %02X%02X%02X%02X%02X%02X%02X%02X"
			"%02X%02X%02X%02X%02X%02X%02X%02X"
			"%02X%02X%02X%02X%02X%02X%02X%02X"
			"%02X%02X%02X%02X%02X%02X%02X%02X"
			"%02X%02X%02X%02X%02X%02X%02X%02X"
			"%02X%02X%02X%02X%02X%02X%02X%02X"
			"%02X%02X%02X%02X%02X%02X%02X%02X"
			"%02X%02X%02X%02X%02X%02X%02X%02X",
			sha_md[0], sha_md[1], sha_md[2], sha_md[3],sha_md[4], sha_md[5], sha_md[6], sha_md[7], 
			sha_md[8], sha_md[9], sha_md[10], sha_md[11],sha_md[12], sha_md[13], sha_md[14], sha_md[15], 

			sha_md[16], sha_md[17], sha_md[18], sha_md[19], sha_md[20], sha_md[21], sha_md[22], sha_md[23],
			sha_md[24], sha_md[25], sha_md[26], sha_md[27],sha_md[28], sha_md[29], sha_md[30], sha_md[31],
			
			sha_md[32], sha_md[33], sha_md[34], sha_md[35], sha_md[36], sha_md[37], sha_md[38], sha_md[39],
			sha_md[40], sha_md[41], sha_md[42], sha_md[43],sha_md[44], sha_md[45], sha_md[46], sha_md[47],
			
			sha_md[48], sha_md[49], sha_md[50], sha_md[51], sha_md[52], sha_md[53], sha_md[54], sha_md[55],
			sha_md[56], sha_md[57], sha_md[58], sha_md[59],sha_md[60], sha_md[61], sha_md[62], sha_md[63]
			);
		m_mdList.SetItemText(MessageDigest_SHA3_512, 0, strMessageDigest);
	}

	
	//self define crc mode.
	if(m_strPoly != _T("") && m_dwDataWidth) {
		char *lptmp = NULL;
		const size_t bits = (size_t)m_dwDataWidth;
		const unsigned long poly = strtoul(m_strPoly, &lptmp, 16);
		const unsigned long init = strtoul(m_strInitValue, &lptmp, 16);
		const unsigned long out  = strtoul(m_strOut, &lptmp, 16);
		const bool inf = m_bInReflect?true:false;
		const bool outf = m_bOutReflect?true:false;
		unsigned long rem = 0;

		if(!((poly == ULONG_MAX && errno == ERANGE) || *lptmp != 0)) {
	//		boost::crc_optimal<bits, poly, init, out, inf, ino> crc_self;
			switch (bits) {
#define CALC_CRC_BITS(nbits)	\
			case nbits:  {		\
				boost::crc_basic<nbits> crc(poly, init, out, inf, outf);\
				crc.process_bytes((unsigned char *)pData, dwFileSize);	\
				rem = crc.checksum();	\
				break;					\
				}
			CALC_CRC_BITS(1);	CALC_CRC_BITS(2);	CALC_CRC_BITS(3);
			CALC_CRC_BITS(4);	CALC_CRC_BITS(5);	CALC_CRC_BITS(6);
			CALC_CRC_BITS(7);	CALC_CRC_BITS(8);	CALC_CRC_BITS(9);
			CALC_CRC_BITS(10);	CALC_CRC_BITS(11);	CALC_CRC_BITS(12);
			CALC_CRC_BITS(13);	CALC_CRC_BITS(14);	CALC_CRC_BITS(15);
			CALC_CRC_BITS(16);	CALC_CRC_BITS(17);	CALC_CRC_BITS(18);
			CALC_CRC_BITS(19);	CALC_CRC_BITS(20);	CALC_CRC_BITS(21);
			CALC_CRC_BITS(22);	CALC_CRC_BITS(23);	CALC_CRC_BITS(24);
			CALC_CRC_BITS(25);	CALC_CRC_BITS(26);	CALC_CRC_BITS(27);
			CALC_CRC_BITS(28);	CALC_CRC_BITS(29);	CALC_CRC_BITS(30);
			CALC_CRC_BITS(31);	CALC_CRC_BITS(32);/*	CALC_CRC_BITS(33);
			CALC_CRC_BITS(34);	CALC_CRC_BITS(35);	CALC_CRC_BITS(36);
			CALC_CRC_BITS(37);	CALC_CRC_BITS(38);	CALC_CRC_BITS(39);
			CALC_CRC_BITS(40);	CALC_CRC_BITS(41);	CALC_CRC_BITS(42);
			CALC_CRC_BITS(43);	CALC_CRC_BITS(44);	CALC_CRC_BITS(45);
			CALC_CRC_BITS(46);	CALC_CRC_BITS(47);	CALC_CRC_BITS(48);
			CALC_CRC_BITS(49);	CALC_CRC_BITS(50);	CALC_CRC_BITS(51);
			CALC_CRC_BITS(52);	CALC_CRC_BITS(53);	CALC_CRC_BITS(54);
			CALC_CRC_BITS(55);	CALC_CRC_BITS(56);	CALC_CRC_BITS(57);
			CALC_CRC_BITS(58);	CALC_CRC_BITS(59);	CALC_CRC_BITS(60);
			CALC_CRC_BITS(61);	CALC_CRC_BITS(62);	CALC_CRC_BITS(63);
			CALC_CRC_BITS(64);	CALC_CRC_BITS(65);	CALC_CRC_BITS(66);
			CALC_CRC_BITS(67);	CALC_CRC_BITS(68);	CALC_CRC_BITS(69);*/
			default: break;
			}

			m_strSelfCRC.Format(_T("%%0%dX"), bits / 8);
			strMessageDigest.Format(m_strSelfCRC, rem);
			m_strSelfCRC = strMessageDigest;
#undef CALC_CRC_BITS
		}
	}

done:
	UpdateData(FALSE);
	UnmapViewOfFile(pvFile);
	CloseHandle(hFileMap);
	CloseHandle(hFile);
	return ;
}
Example #7
0
void sha256(byte* digest, string arg)
{
    CryptoPP::SHA256 hashfun;
    hashfun.CalculateDigest(digest, (byte*) arg.c_str(), arg.length());
}
Example #8
-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);
}