本文整理汇总了C++中MD5::digestString方法的典型用法代码示例。如果您正苦于以下问题:C++ MD5::digestString方法的具体用法?C++ MD5::digestString怎么用?C++ MD5::digestString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MD5
的用法示例。
在下文中一共展示了MD5::digestString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: checkPass
void checkPass(char* hashFile, char* tempString, int myRank, char* type)
{
int i;
bool foundPass = false;
char str[SHA256_HASH_LENGTH+1];
char testHash[SHA256_HASH_LENGTH+1];
if (strcmp(type, "MD5") == 0)
{
sprintf(testHash, "%s", md5.digestString(tempString));
}
else if (strcmp(type, "SHA1") == 0)
{
unsigned char binaryHash[SHA_DIGEST_LENGTH];
unsigned char* sha1String = (unsigned char*)tempString;
SHA1(sha1String, strlen(tempString), binaryHash);
for (i = 0; i < SHA_DIGEST_LENGTH; i++)
sprintf(testHash+2*i, "%02x", binaryHash[i]);
}
else if (strcmp(type, "SHA256") == 0)
{
unsigned char binaryHash[SHA256_DIGEST_LENGTH];
unsigned char* sha256String = (unsigned char*)tempString;
SHA256(sha256String, strlen(tempString), binaryHash);
for (i = 0; i < SHA256_DIGEST_LENGTH; i++)
sprintf(testHash+2*i, "%02x", binaryHash[i]);
}
// printf("Proc %d: %s\n", myRank, tempString); // Debugging info
FILE* pFile;
pFile = fopen (hashFile,"r");
if (pFile == NULL) {
perror ("Error opening file, aborting\n");
MPI_Finalize();
exit(-3);
}
while (fscanf (pFile, "%s", str) != EOF)
{
foundPass = (strcmp(testHash, str) == 0);
if (foundPass) {
printf("%s, %s\n", tempString, testHash);
}
}
fclose (pFile);
}
示例2: checkPass
void checkPass(char* hash, char* tempString)
{
char testHash[HASH_LENGTH];
int i;
bool foundPass = false;
sprintf(testHash, "%s", md5.digestString(tempString));
// printf("%s\n", tempString);
for (i = 0; i < HASH_LENGTH; i++) {// Checks if the hashes match
if (testHash[i] != hash[i]) {
foundPass = false;
break;
} else {
foundPass = true;
}
}
if (foundPass) {
printf("The password is %s\n", tempString);
exit(0);
}
}