本文整理汇总了C++中MD5类的典型用法代码示例。如果您正苦于以下问题:C++ MD5类的具体用法?C++ MD5怎么用?C++ MD5使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MD5类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: lock
bool RelaxNGValidator::LoadGrammar(const std::string& grammar)
{
shared_ptr<RelaxNGSchema> schema;
{
CScopeLock lock(g_SchemaCacheLock);
std::map<std::string, shared_ptr<RelaxNGSchema> >::iterator it = g_SchemaCache.find(grammar);
if (it == g_SchemaCache.end())
{
schema = shared_ptr<RelaxNGSchema>(new RelaxNGSchema(grammar));
g_SchemaCache[grammar] = schema;
}
else
{
schema = it->second;
}
}
m_Schema = schema->m_Schema;
if (!m_Schema)
return false;
MD5 hash;
hash.Update((const u8*)grammar.c_str(), grammar.length());
m_Hash = hash;
return true;
}
示例2: md5buff
void md5buff(const char* _in, char *_out, size_t _size_in)
{
MD5_CTX m_md5_ctx;
MD5 m;
m.MD5Init ( &m_md5_ctx );
m.MD5Update ( &m_md5_ctx, (unsigned char*)_in, _size_in);
m.MD5Final ( (unsigned char*)_out, &m_md5_ctx);
}
示例3: IPacket
IUserPacket::IUserPacket(LPCTSTR xUserId, LPCTSTR xPass) : IPacket( ICP_USER )
{
MD5 ctx; BYTE xMD5Hash[16];
ctx.update( (LPBYTE)xPass, _tcslen(xPass) );
ctx.finalize(); ctx.raw_digest( xMD5Hash );
CopyMemory( UserId, xUserId, 21 );
ctx.tostring( (LPBYTE)MD5Hashing );
}
示例4: CalcHashBytes
int CalcHashBytes(LPTSTR xHashing, LPCTSTR xString)
{
MD5 ctx; BYTE pHash[16];
ctx.update( (LPBYTE)xString, _tcslen(xString) );
ctx.finalize(); ctx.raw_digest( pHash );
ctx.tostring( (LPBYTE)xHashing );
return 32;
}
示例5: fileIn
void FileCodeWriter::WriteBuffer()
{
const static unsigned char MICROSOFT_BOM[3] = { 0xEF, 0xBB, 0xBF };
// Compare buffer with existing file (if any) to determine if
// writing the file is necessary
bool shouldWrite = true;
std::ifstream fileIn(m_filename.mb_str(wxConvFile), std::ios::binary | std::ios::in);
std::string buf;
if (fileIn)
{
MD5 diskHash(fileIn);
unsigned char* diskDigest = diskHash.raw_digest();
MD5 bufferHash;
if (m_useMicrosoftBOM) {
bufferHash.update(MICROSOFT_BOM, 3);
}
const std::string& data = m_useUtf8 ? _STDSTR( m_buffer ) : _ANSISTR( m_buffer );
if (!m_useUtf8) buf = data;
bufferHash.update( reinterpret_cast< const unsigned char* >( data.c_str() ), data.size() );
bufferHash.finalize();
unsigned char* bufferDigest = bufferHash.raw_digest();
shouldWrite = ( 0 != std::memcmp( diskDigest, bufferDigest, 16 ) );
delete [] diskDigest;
delete [] bufferDigest;
}
if ( shouldWrite )
{
wxFile fileOut;
if (!fileOut.Create(m_filename, true))
{
wxLogError( _("Unable to create file: %s"), m_filename.c_str() );
return;
}
if (m_useMicrosoftBOM)
{
fileOut.Write(MICROSOFT_BOM, 3);
}
if (!m_useUtf8)
fileOut.Write(buf.c_str(), buf.length());
else
fileOut.Write(m_buffer);
}
}
示例6: md5string
/*
* @brief Calculate MD5 value
*/
void md5string(const char* _in, char *_out)
{
MD5_CTX m_md5_ctx;
MD5 m;
m.MD5Init ( &m_md5_ctx );
m.MD5Update ( &m_md5_ctx, (unsigned char*)_in, strlen(_in));
m.MD5Final ( (unsigned char*)_out, &m_md5_ctx);
}
示例7:
const wxString wxMD5::GetDigest()
{
MD5 context;
context.update((unsigned char*)m_szText.mb_str().data(), m_szText.Len());
context.finalize();
wxString md5(context.hex_digest());
md5.MakeUpper();
return md5;
}
示例8: addMessageId
void Message::addMessageId()
{
if ( header()->field( HeaderField::MessageId ) )
return;
MD5 x;
x.add( rfc822() );
header()->add( "Message-Id",
"<" + x.hash().e64().mid( 0, 21 ) + "[email protected]" +
Configuration::hostname() + ">" );
}
示例9: md5
UnicodeString __fastcall md5(UnicodeString Pass)
{
wchar_t *ww;
MD5 *md;
ww = Pass.w_str();
std::wstring wstr = ww;
std::string str = std::string(wstr.begin(), wstr.end());
md = new MD5();
md->add(str.c_str(), str.length());
str = md->getHash();
return UnicodeString(str.c_str());
}
示例10: MD5
void Hashr::md5Hash(const char* file, path hash_item) {
MD5 hash = MD5(file, 32);
hashValue = hash.getHash();
ofstream fout; fout.open("C:/Users/darry/Desktop/MD5_HashTable.txt", ofstream::app);
fout << hashValue << endl;
fout.close();
//cout << "MD5: " << hashValue << endl;
//cout << "MD5HashTable value: " << md5Table[hashValue] << endl;
if (md5Table[hashValue] == hashValue) {
suspect = true;
}
}
示例11: l
bool CdbInterface::authenticate(const char* username, const char* password)
{
SingleLock l(&dbMutex_);
if (!l.lock())
return false;
ReadLockSQLTable sqlLock(dbase_, "pokeruser");
if (!sqlLock.success_)
return false;
char query[MAXQUERYSIZE];
char* dbPassword = NULL;
MD5 context;
string u = sqlfy(username);
context.update((unsigned char *)password, (int)strlen(password));
context.finalize();
memset(query, 0x0, MAXQUERYSIZE);
sprintf(query, "SELECT password FROM pokeruser WHERE username='%s'", u.c_str());
if (!dbase_->dbQuery(query))
{
if (DEBUG & DEBUG_DATABASE)
{
printf("Query to authenticate %s failed!\n", username);
printf("Reason: %s\n", mysql_error(dbase_->mySQLQuery_));
}
return false;
}
dbPassword = dbase_->dbFetchRow();
if (dbPassword == NULL)
{
char s[200];
sprintf(s, "CTable::tableLogin: User %s does not exist in database!", username);
Sys_LogError(s);
return false;
}
else if (strcmp(dbPassword, context.hex_digest()))
{
char s[200];
sprintf(s, "CTable::tableLogin: wrong password %s for user %s.", password, username);
Sys_LogError(s);
return false;
}
return true;
};
示例12: hashString
static void hashString(MD5& md5, const String& string)
{
const uint8_t zero = 0;
if (string.is8Bit() && string.containsOnlyASCII()) {
md5.addBytes(string.characters8(), string.length());
md5.addBytes(&zero, 1);
return;
}
auto cString = string.utf8();
md5.addBytes(reinterpret_cast<const uint8_t*>(cString.data()), cString.length());
md5.addBytes(&zero, 1);
}
示例13: main
int main(int argc, char ** argv)
{
unsigned int iterations = 1 << 15;
unsigned int tests = 10000;
unsigned char salt1[] = {0x97, 0x48, 0x6C, 0xAA, 0x22, 0x5F, 0xE8, 0x77, 0xC0, 0x35, 0xCC, 0x03, 0x73, 0x23, 0x6D, 0x51};
char path[] = "C:\\Documents and Settings\\john\\Local Settings\\Application Data\\Google\\Chrome\\Application~dir1";
unsigned char null = 0x00;
cout << "Number of tests: " << iterations << endl;
cout << "Iterations per hash: " << tests << endl;
int start = clock();
for(int y = 0; y < iterations; y++)
{
MD5 md5;
for(int x = 0; x < strlen(path); x++)
{
md5.update((unsigned char *)path + x, 1);
md5.update((unsigned char *)&null, 1);
}
md5.update(salt1, 16);
unsigned char hash[16];
md5.finalize();
memcpy(hash, md5.digest, 16);
for(int x = 0; x < tests; x++)
{
MD5 m;
m.update(hash, 16);
m.finalize();
memcpy(hash, m.digest, 16);
}
}
int end = clock();
double orig = end - start;
printf ("Original: (%f seconds) %f hashes per second.\n", ((float)end - start)/CLOCKS_PER_SEC, ((double)iterations + 1)/(((float)end - start)/CLOCKS_PER_SEC));
start = clock();
for(int y = 0; y < iterations; y++)
{
MD5 md5i;
for(int x = 0; x < strlen(path); x++)
{
md5i.update((unsigned char *)path + x, 1);
md5i.update((unsigned char *)&null, 1);
}
md5i.update(salt1, 16);
md5i.finalize(tests);
}
end = clock();
orig = end - start;
printf ("Original: (%f seconds) %f hashes per second.\n", ((float)end - start)/CLOCKS_PER_SEC, ((double)iterations + 1)/(((float)end - start)/CLOCKS_PER_SEC));
cout << endl << "Should be 76405ce7f4e75e352c1cd4d9aeb6be41" << endl;
}
示例14: TestMD5
inline void TestMD5() {
// echo -n 'qwertyuiopqwertyuiopasdfghjklasdfghjkl' | md5sum
char b[] = "qwertyuiopqwertyuiopasdfghjklasdfghjkl";
MD5 r;
r.Update((const unsigned char*)b, 15);
r.Update((const unsigned char*)b + 15, strlen(b) - 15);
char rs[33];
Stroka s(r.End(rs));
s.to_lower();
UNIT_ASSERT_EQUAL(s, Stroka("3ac00dd696b966fd74deee3c35a59d8f"));
}
示例15: sqlLock
bool CdbInterface::authenticate(const char* username, const char* password)
{
ReadLockSQLTable sqlLock(dbase_, "pokeruser");
CStrOut query;
char* dbPassword = NULL;
string u = sqlfy(username);
MD5 context;
context.update((unsigned char*)password, strlen(password));
context.finalize();
query << "SELECT password FROM pokeruser WHERE username='"
<< u.c_str() << '\'';
if (!dbase_->dbQuery(query.str()))
{
if (DEBUG & DEBUG_DATABASE)
{
printf("Query to authenticate %s failed!\n", username);
}
return false;
}
dbPassword = dbase_->dbFetchRow();
if (dbPassword == NULL)
{
if (DEBUG & DEBUG_DATABASE)
{
printf("User %s does not exist in database!\n", username);
}
return false;
}
//MP
else if (strcmp(dbPassword, password))
{
if (DEBUG & DEBUG_DATABASE)
{
printf("User supplied password and password on file don't match!\n");
}
return false;
}
return true;
};