本文整理汇总了C++中MD5::update方法的典型用法代码示例。如果您正苦于以下问题:C++ MD5::update方法的具体用法?C++ MD5::update怎么用?C++ MD5::update使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MD5
的用法示例。
在下文中一共展示了MD5::update方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: WriteBuffer
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);
}
}
示例2: hashRouter
/**
* Generate BMP router HASH
*
* \param [in,out] client Reference to client info used to generate the hash.
*
* \return client.hash_id will be updated with the generated hash
*/
void BMPListener::hashRouter(ClientInfo &client) {
string c_hash_str;
MsgBusInterface::hash_toStr(cfg->c_hash_id, c_hash_str);
MD5 hash;
hash.update((unsigned char *)client.c_ip, strlen(client.c_ip));
hash.update((unsigned char *)c_hash_str.c_str(), c_hash_str.length());
hash.finalize();
// Save the hash
unsigned char *hash_bin = hash.raw_digest();
memcpy(client.hash_id, hash_bin, 16);
delete[] hash_bin;
}
示例3: 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;
}
示例4: 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 );
}
示例5:
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;
}
示例6: authenticate
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;
};
示例7: 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;
}
示例8: authenticate
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;
};
示例9:
TEST( Utils, MD5 )
{
MD5 checksum;
// abc
checksum.update("abc");
EXPECT_EQ( "900150983cd24fb0d6963f7d28e17f72", checksum.final_hex() );
// abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq
checksum.update("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq");
EXPECT_EQ( "8215ef0796a20bcaaae116d3876c664a", checksum.final_hex() );
// A million repetitions of 'a'.
for (int i = 0; i < 1000000/200; ++i)
{
checksum.update(
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
);
}
EXPECT_EQ( "7707d6ae4e027c70eea2a935c2296f21", checksum.final_hex() );
// No string
EXPECT_EQ( "d41d8cd98f00b204e9800998ecf8427e", checksum.final_hex());
// Empty string
checksum.update("");
EXPECT_EQ( "d41d8cd98f00b204e9800998ecf8427e", checksum.final_hex());
// Two concurrent checksum calculations
MD5 checksum1, checksum2;
checksum1.update("abc");
EXPECT_EQ( "900150983cd24fb0d6963f7d28e17f72", checksum1.final_hex());
EXPECT_EQ( "d41d8cd98f00b204e9800998ecf8427e", checksum2.final_hex());
}
示例10: output_directory
void output_directory( set< string >& file_names,
const string& path_name, int level, ofstream& outf, bool use_zlib, gzFile& gzf )
#endif
{
string::size_type pos = path_name.find_last_of( '/' );
if( level > 1 && pos != string::npos && !g_output_directories.count( path_name.substr( 0, pos ) ) )
{
#ifndef ZLIB_SUPPORT
output_directory( file_names, path_name.substr( 0, pos ), level - 1, outf );
#else
output_directory( file_names, path_name.substr( 0, pos ), level - 1, outf, use_zlib, gzf );
#endif
}
if( !file_names.count( path_name ) )
{
string rel_path( "." );
string::size_type pos = path_name.find( '/' );
if( pos != string::npos )
rel_path += path_name.substr( pos );
string perms = file_perms( rel_path );
MD5 md5;
md5.update( ( unsigned char* )perms.c_str( ), perms.length( ) );
md5.update( ( unsigned char* )path_name.c_str( ), path_name.length( ) );
md5.finalize( );
auto_ptr< char > ap_digest( md5.hex_digest( ) );
ostringstream osstr;
osstr << "D " << level << ' ' << perms << ' ' << path_name << ' ' << ap_digest.get( );
g_md5.update( ( unsigned char* )ap_digest.get( ), 32 );
#ifndef ZLIB_SUPPORT
outf << osstr.str( ) << '\n';
#else
if( !use_zlib )
outf << osstr.str( ) << '\n';
else
write_zlib_line( gzf, osstr.str( ) );
#endif
file_names.insert( path_name );
}
g_output_directories.insert( path_name );
}
示例11: createTestPlayers
// This mfunction creates 'numPlayers' player entries
// with username and password 'bot_X'.
bool CdbInterface::createTestPlayers(int numPlayers)
{
bool rc = true;
for (int i = 0; i < numPlayers; i++)
{
char buf[17];
sprintf(buf, "bot_%i", i + 1);
// First check that the player is not already there!
char query[MAXQUERYSIZE];
sprintf(query, "SELECT username FROM pokeruser where username='%s';",
buf);
if (!dbase_->dbQuery(query))
{
Sys_LogError("Query to create test player failed(0).");
return false;
}
const char* fetched = dbase_->dbFetchRow();
if (fetched == NULL)
{ // Okay now create the player
MD5 context;
context.update((unsigned char*)buf, strlen(buf));
context.finalize();
sprintf(query, "INSERT INTO customers (username, password, cc1_type, cc1_number, spam) VALUES ('%s', '%s', 'asiV', '1', 1);",
buf, context.hex_digest());
if (!dbase_->dbQuery(query))
{
Sys_LogError("Query to create test player failed(1).");
return false;
}
sprintf(query, "INSERT INTO pokeruser (username, password) VALUES ('%s', '%s');",
buf, context.hex_digest());
if (!dbase_->dbQuery(query))
{
Sys_LogError("Query to create test player failed(2).");
return false;
}
}
}
return true;
}
示例12:
static void md5_block(MD5& md5, const Pel* plane, unsigned n)
{
/* create a 64 byte buffer for packing Pel's into */
unsigned char buf[64/OUTPUT_BITDEPTH_DIV8][OUTPUT_BITDEPTH_DIV8];
for (unsigned i = 0; i < n; i++)
{
Pel pel = plane[i];
/* perform bitdepth and endian conversion */
for (unsigned d = 0; d < OUTPUT_BITDEPTH_DIV8; d++)
{
buf[i][d] = pel >> (d*8);
}
}
md5.update((unsigned char*)buf, n * OUTPUT_BITDEPTH_DIV8);
}
示例13: main
void main()
{
HMODULE hVDLL;
IBaseVerify* pCV;
_NxModule_GetType NxModule_GetType;
_NxVerify_GetInterface NxVerify_GetInterface;
size_t cEncode_Id = 1;
// _GetVersion pGetVersion;
hVDLL = LoadLibrary("NxVerify.dll");
NxModule_GetType = (_NxModule_GetType)GetProcAddress(hVDLL, "NxModule_GetType");
NxVerify_GetInterface = (_NxVerify_GetInterface)GetProcAddress(hVDLL, "NxVerify_GetInterface");
pCV = NxVerify_GetInterface();
unsigned char buf[128];
ZeroMemory(buf, sizeof(buf));
//memcpy(buf, (const char*)"A", sizeof("A"));
MD5 alg;
alg.update(buf, sizeof(buf));
alg.finalize();
UI08 output[16];
unsigned int *p;
p = (unsigned int *)alg.digest;
for (int i = 0; i < 4; i++)
{
printf("0x%08x\n", *p);
p++;
}
pCV->EncodeFunc(cEncode_Id, alg.digest, output);
p = (unsigned int *)output;
for (int i = 0; i < 4; i++)
{
printf("0x%08x\n", *p);
p++;
}
getchar();
}
示例14: process_directory
//.........这里部分代码省略.........
output_directory( file_names, path_name, dfsi.get_level( ), outf, use_zlib, gzf );
#endif
}
if( !is_quieter )
{
string next_path( path_name );
if( next_path.find( directory ) == 0 )
{
next_path.erase( 0, directory.size( ) );
if( !next_path.empty( ) && next_path[ 0 ] == '/' )
next_path.erase( 0, 1 );
}
if( !next_path.empty( ) )
next_path += "/";
cout << "adding \"" << next_path << ffsi.get_name( ) << "\"";
}
int64_t size = file_size( ffsi.get_full_name( ) );
string perms = file_perms( ffsi.get_full_name( ) );
string fname( ffsi.get_name( ) );
ifstream inpf( ffsi.get_full_name( ).c_str( ), ios::in | ios::binary );
if( !inpf )
throw runtime_error( "unable to open file '" + ffsi.get_full_name( ) + "' for input" );
MD5 md5;
unsigned char buffer[ c_buffer_size ];
md5.update( ( unsigned char* )perms.c_str( ), perms.length( ) );
md5.update( ( unsigned char* )fname.c_str( ), fname.length( ) );
int64_t size_left = size;
while( size_left )
{
int next_len = c_buffer_size;
if( size_left < c_buffer_size )
next_len = ( int )size_left;
inpf.read( ( char* )buffer, next_len );
int len = inpf.gcount( );
md5.update( buffer, len );
size_left -= next_len;
}
md5.finalize( );
inpf.seekg( 0, ios::beg );
int max_size = c_max_bytes_per_line;
if( encoding != e_encoding_type_b64 )
max_size = c_buffer_size;
int64_t num;
if( encoding == e_encoding_type_raw )
num = size;
else
{
num = size / max_size;
if( size % max_size )
++num;
}
示例15: add_Rib
/**
* Abstract method Implementation - See DbInterface.hpp for details
*/
void mysqlBMP::add_Rib(vector<tbl_rib> &rib_entry) {
char *buf = new char[800000]; // Misc working buffer
char buf2[4096]; // Second working buffer
size_t buf_len = 0; // query buffer length
try {
// Build the initial part of the query
//buf_len = sprintf(buf, "REPLACE into %s (%s) values ", TBL_NAME_RIB,
// "hash_id,path_attr_hash_id,peer_hash_id,prefix, prefix_len");
buf_len = sprintf(buf, "INSERT into %s (%s) values ", TBL_NAME_RIB,
"hash_id,path_attr_hash_id,peer_hash_id,prefix, prefix_len,timestamp");
string rib_hash_str;
string path_hash_str;
string p_hash_str;
// Loop through the vector array of rib entries
for (size_t i = 0; i < rib_entry.size(); i++) {
/*
* Generate router table hash from the following fields
* rib_entry.peer_hash_id, rib_entry.prefix, rib_entry.prefix_len
*
*/
MD5 hash;
// Generate the hash
hash.update(rib_entry[i].peer_hash_id, HASH_SIZE);
hash.update((unsigned char *) rib_entry[i].prefix,
strlen(rib_entry[i].prefix));
hash.update(&rib_entry[i].prefix_len,
sizeof(rib_entry[i].prefix_len));
hash.finalize();
// Save the hash
unsigned char *hash_raw = hash.raw_digest();
memcpy(rib_entry[i].hash_id, hash_raw, 16);
delete[] hash_raw;
// Build the query
hash_toStr(rib_entry[i].hash_id, rib_hash_str);
hash_toStr(rib_entry[i].path_attr_hash_id, path_hash_str);
hash_toStr(rib_entry[i].peer_hash_id, p_hash_str);
buf_len += snprintf(buf2, sizeof(buf2),
" ('%s','%s','%s','%s', %d, from_unixtime(%u)),", rib_hash_str.c_str(),
path_hash_str.c_str(), p_hash_str.c_str(),
rib_entry[i].prefix, rib_entry[i].prefix_len,
rib_entry[i].timestamp_secs);
// Cat the entry to the query buff
if (buf_len < 800000 /* size of buf */)
strcat(buf, buf2);
}
// Remove the last comma since we don't need it
buf[buf_len - 1] = 0;
// Add the on duplicate statement
snprintf(buf2, sizeof(buf2),
" ON DUPLICATE KEY UPDATE timestamp=values(timestamp),path_attr_hash_id=values(path_attr_hash_id),db_timestamp=current_timestamp");
strcat(buf, buf2);
SELF_DEBUG("QUERY=%s", buf);
// Run the query to add the record
stmt = con->createStatement();
stmt->execute(buf);
// Free the query statement
delete stmt;
} catch (sql::SQLException &e) {
LOG_ERR("mysql error: %s, error Code = %d, state = %s",
e.what(), e.getErrorCode(), e.getSQLState().c_str() );
}
// Free the large buffer
delete[] buf;
}