本文整理汇总了C++中MD5::finalize方法的典型用法代码示例。如果您正苦于以下问题:C++ MD5::finalize方法的具体用法?C++ MD5::finalize怎么用?C++ MD5::finalize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MD5
的用法示例。
在下文中一共展示了MD5::finalize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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 );
}
示例2: 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);
}
}
示例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:
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;
}
示例5: 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;
};
示例6: 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;
}
示例7: 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;
}
示例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: 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;
}
示例10: 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();
}
示例11: 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;
}
示例12: main
//.........这里部分代码省略.........
throw runtime_error( "unexpected format in line #" + to_string( line ) );
string rwx_perms( next.substr( 0, pos ) );
next.erase( 0, pos + 1 );
if( is_delete && all_filespecs.empty( ) )
{
for( int i = first_arg + 2; i < argc; i++ )
all_filespecs[ c_delete_dummy_path ].push_back( next + '/' + string( argv[ i ] ) );
}
current_sub_path = next;
if( file_names.count( next ) )
continue;
else
{
pos = next.find( '/' );
if( !is_quieter && pos != string::npos )
cout << "append \"" << next.substr( pos + 1 ) << "/\"\n";
file_names.insert( next );
g_md5.update( ( unsigned char* )check.c_str( ), check.length( ) );
}
}
else if( type == c_type_checksum )
break;
else
throw runtime_error( "unexpected entry type '" + to_string( type ) + "' found in line #" + to_string( line ) );
#ifndef ZLIB_SUPPORT
outf << next_line << '\n';
#else
if( !use_zlib )
outf << next_line << '\n';
else
write_zlib_line( gzf, next_line );
#endif
}
}
#ifdef ZLIB_SUPPORT
if( use_zlib )
gzclose( igzf );
#endif
}
g_md5.finalize( );
ostringstream osstr;
auto_ptr< char > ap_digest( g_md5.hex_digest( ) );
osstr << "C " << ap_digest.get( );
#ifndef ZLIB_SUPPORT
outf << osstr.str( ) << '\n';
#else
if( !use_zlib )
outf << osstr.str( ) << '\n';
else
write_zlib_line( gzf, osstr.str( ) );
#endif
#ifdef ZLIB_SUPPORT
if( use_zlib )
gzclose( gzf );
#endif
if( !use_zlib )
{
outf.flush( );
if( !outf.good( ) )
throw runtime_error( "unexpected write failure for output file '" + filename + "'" );
}
}
if( is_append )
{
if( !file_remove( filename ) || rename( output_filename.c_str( ), filename.c_str( ) ) != 0 )
throw runtime_error( "unable to replace original '" + filename + "' with '" + output_filename + "'" );
if( is_delete && !is_quieter && num_deleted == 0 )
cout << "warning: found no matching files to delete" << endl;
}
else if( matched_filters.empty( ) )
{
file_remove( filename );
throw runtime_error( "*** nothing to do ***" );
}
if( !is_quiet )
cout << "==> finished bundling '" << filename << "'" << endl;
}
catch( exception& x )
{
cerr << "error: " << x.what( ) << endl;
return 1;
}
return 0;
}
示例13: add_Router
/**
* Abstract method Implementation - See DbInterface.hpp for details
*/
void mysqlBMP::add_Router(tbl_router &r_entry) {
try {
char buf[4096]; // Misc working buffer
/*
* Generate router table hash from the following fields
* r_entry.name, r_entry.src_addr
*
*/
MD5 hash;
// Generate the hash
//hash.update (r_entry.name, strlen((char *)r_entry.name));
hash.update(r_entry.src_addr, strlen((char *) r_entry.src_addr));
hash.finalize();
// Save the hash
unsigned char *hash_raw = hash.raw_digest();
memcpy(r_entry.hash_id, hash_raw, 16);
delete [] hash_raw;
// Convert binary hash to string
string r_hash_str;
hash_toStr(r_entry.hash_id, r_hash_str);
// Check if we have already processed this entry, if so update it an return
if (router_list.find(r_hash_str) != router_list.end()) {
router_list[r_hash_str] = time(NULL);
return;
}
// Insert/Update map entry
router_list[r_hash_str] = time(NULL);
// Convert the init data to string for storage
string initData(r_entry.initiate_data);
std::replace(initData.begin(), initData.end(), '\'', '"');
// Build the query
snprintf(buf, sizeof(buf),
"INSERT into %s (%s) values ('%s', '%s', '%s','%s','%s')",
TBL_NAME_ROUTERS, "hash_id,name,description,ip_address,init_data", r_hash_str.c_str(),
r_entry.name, r_entry.descr, r_entry.src_addr, initData.c_str());
// Add the on duplicate statement
strcat(buf, " ON DUPLICATE KEY UPDATE timestamp=current_timestamp,isConnected=1,name=values(name),description=values(description),init_data=values(init_data)");
// Run the query to add the record
stmt = con->createStatement();
stmt->execute(buf);
// Update all peers to indicate peers are not up - till proven other wise
snprintf(buf, sizeof(buf), "UPDATE %s SET state=0 where router_hash_id='%s'",
TBL_NAME_BGP_PEERS, r_hash_str.c_str());
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() );
}
}
示例14: add_PathAttrs
/**
* Abstract method Implementation - See DbInterface.hpp for details
*/
void mysqlBMP::add_PathAttrs(tbl_path_attr &path_entry) {
try {
char buf[64000]; // Misc working buffer
char buf2[24000]; // Second working buffer
size_t buf_len; // size of the query buff
// Setup the initial MySQL query
buf_len =
sprintf(buf, "INSERT into %s (%s) values ", TBL_NAME_PATH_ATTRS,
"hash_id,peer_hash_id,origin,as_path,next_hop,med,local_pref,isAtomicAgg,aggregator,community_list,ext_community_list,cluster_list,originator_id,origin_as,as_path_count,timestamp");
/*
* Generate router table hash from the following fields
* peer_hash_id, as_path, next_hop, aggregator,
* origin, med, local_pref
*
*/
MD5 hash;
// Generate the hash
hash.update(path_entry.peer_hash_id, HASH_SIZE);
hash.update((unsigned char *) path_entry.as_path,
strlen(path_entry.as_path));
hash.update((unsigned char *) path_entry.next_hop,
strlen(path_entry.next_hop));
hash.update((unsigned char *) path_entry.aggregator,
strlen(path_entry.aggregator));
hash.update((unsigned char *) path_entry.origin,
strlen(path_entry.origin));
hash.update((unsigned char *) &path_entry.med, sizeof(path_entry.med));
hash.update((unsigned char *) &path_entry.local_pref,
sizeof(path_entry.local_pref));
hash.finalize();
// Save the hash
unsigned char *hash_raw = hash.raw_digest();
memcpy(path_entry.hash_id, hash_raw, 16);
delete[] hash_raw;
// Build the query
string path_hash_str;
string p_hash_str;
hash_toStr(path_entry.hash_id, path_hash_str);
hash_toStr(path_entry.peer_hash_id, p_hash_str);
buf_len +=
snprintf(buf2, sizeof(buf2),
"('%s','%s','%s','%s','%s', %u,%u,%d,'%s','%s','%s','%s','%s','%"PRIu32"','%hu', from_unixtime(%u)),",
path_hash_str.c_str(), p_hash_str.c_str(),
path_entry.origin, path_entry.as_path,
path_entry.next_hop, path_entry.med,
path_entry.local_pref, path_entry.atomic_agg,
path_entry.aggregator, path_entry.community_list,
path_entry.ext_community_list, path_entry.cluster_list,
path_entry.originator_id, path_entry.origin_as,
path_entry.as_path_count,
path_entry.timestamp_secs);
// Cat the string to our query buffer
if (buf_len < sizeof(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) ");
strcat(buf, buf2);
SELF_DEBUG("QUERY=%s\n", 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() );
}
}
示例15: main
//.........这里部分代码省略.........
#ifdef ZLIB_SUPPORT
if( use_zlib )
{
if( !gzread( gzf, buffer, count ) )
throw runtime_error( "reading zlib input" );
}
else
{
if( inpf.rdbuf( )->sgetn( buffer, count ) != count )
throw runtime_error( "reading file input" );
}
#else
if( inpf.rdbuf( )->sgetn( buffer, count ) != count )
throw runtime_error( "reading file input" );
#endif
if( !is_quieter && ++chunk % c_progress_lines == 0 )
{
if( line == c_progress_lines )
cout << ' ';
cout << '.';
cout.flush( );
}
md5.update( ( unsigned char* )buffer, count );
ap_ofstream->rdbuf( )->sputn( buffer, count );
if( !ap_ofstream->good( ) )
throw runtime_error( "unexpected bad output file stream" );
raw_file_size -= count;
}
md5.finalize( );
auto_ptr< char > ap_digest( md5.hex_digest( ) );
if( next_md5 != string( ap_digest.get( ) ) )
cerr << "*** error: file '" << next_file << "' failed MD5 digest check ***" << endl;
ap_ofstream.reset( );
file_perms( next_file, rwx_perms );
if( !is_quieter )
cout << endl;
continue;
}
}
#ifdef ZLIB_SUPPORT
if( use_zlib )
{
if( !read_zlib_line( gzf, next ) )
break;
}
else if( !getline( inpf, next ) )
break;
#else
if( !getline( inpf, next ) )
break;
#endif
++line;
if( next.empty( ) )
throw runtime_error( "unexpected empty line #" + to_string( line ) );