私はPHP md5ハッシュと比較しているmd5ハッシュを作成しようとしています。c openssl libからのMD5がphp md5と一致しませんどうですか?
2があることを縫い目はありません同じ以下
私のCコードは、PHPのcompairison
なぜ2つのMD5が同じでないと一緒にいるのですか?
メイクコマンド
gcc -Wall -lssl -o test test.c
コードtest.cの
#include <stdio.h>
#include <openssl/md5.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/md5.h>
#include <time.h>
unsigned char result[MD5_DIGEST_LENGTH];
// Print the MD5 sum as hex-digits.
void print_md5_sum(unsigned char* md, char* md5) {
int i;
for(i=0; i < MD5_DIGEST_LENGTH; i++) {
char temp[3];
snprintf(temp,sizeof(temp),"%02x",md[i]);
if(i == 0){
strncpy(md5,temp,3);
}else{
strncat(md5,temp,MD5_DIGEST_LENGTH);
}
}
printf("md5 is %s \n", md5);
}
int main(int argc, char** argv){
char* file_buffer = "testtest";
char buffer[MD5_DIGEST_LENGTH +1];
MD5((unsigned char*) file_buffer, sizeof(file_buffer), result);
printf("length %i\n", MD5_DIGEST_LENGTH);
print_md5_sum(result,buffer);
printf("%s \n" ,buffer);
return 0;
}
PHPコード
<?php
echo md5("testtest");
?>
結果
PHPのMD5
05a671c66aefea124cc08b76ea6d30bb
CコードのMD5
098f6bcd4621d373cade4e832627b4f6
:あなたは、おそらくより良い、このようなMD5()関数を呼び出している。この場合
。 '05a671c66aefea124cc08b76ea6d30bb'は確かに' testtest''の正確な16進ダイジェストです – NullUserException
FYI:md5( 'test')= 098f6bcd4621d373cade4e832627b4f6 – hakre