kikito / md5.lua

MD5 sum in pure Lua, with no C and no external dependencies
MIT License
326 stars 151 forks source link

Result is not the same when generating MD5 in another way #13

Closed kultz closed 7 years ago

kultz commented 7 years ago

Generating using terminal

mac:Desktop mac$ echo test | md5
d8e8fca2dc0f896fd7cb4cb0031ba249

When i try to implement it using this lib:

local md5 = require 'md5'
print(md5.sumhexa("test"))

Result would be: 098f6bcd4621d373cade4e832627b4f6

Am i doing something wrong ?

pablomayobre commented 7 years ago

I'm pretty sure that the md5 hash for test is 098f6bcd4621d373cade4e832627b4f6 so you are probably doing something wrong in the console, it may be adding whitespace or something. The library is working perfectly fine!

Yeah, it looks like echo adds a newline character at the end so it is actually test\n, try the following command:

$ echo -n test | md5
kultz commented 7 years ago

@Positive07 Yes my bad! I found the problem right after i posted it in here: I probably hashed "test\n" which is included line terminator. Right way is: echo -n "test" | md5 which is exactly 098f6bcd4621d373cade4e832627b4f6 or md5 -s test

kikito commented 7 years ago

Ok, closing this issue then 😊