Why I got different md5 value with " and '

72 views
Skip to first unread message

qiaoxiao

unread,
Mar 31, 2021, 2:59:35 AM3/31/21
to openresty-en

➜  ~ resty -e "ngx.say(ngx.md5("test"))"                                 

d41d8cd98f00b204e9800998ecf8427e

➜  ~ resty -e "ngx.say(ngx.md5('test'))"

098f6bcd4621d373cade4e832627b4f6

Tahoe

unread,
Mar 31, 2021, 3:00:50 AM3/31/21
to openresty-en

➜  ~ resty -v

resty 0.27

nginx version: openresty/1.19.3.1

built by clang 12.0.0 (clang-1200.0.32.27)

built with OpenSSL 1.1.1g  21 Apr 2020 (running with OpenSSL 1.1.1i  8 Dec 2020)

jona...@findmeon.com

unread,
Apr 1, 2021, 1:37:12 PM4/1/21
to openresty-en
`d41d8cd98f00b204e9800998ecf8427e` is the md5 of an empty string, which caught my eye.

one of your one-liners is invalid. resty is probably doing some sort of graceful exit on the exception handling.

this line

    resty -e "ngx.say(ngx.md5("test"))"

is the same as:

    resty -e "ngx.say(ngx.md5("
    +
    test"))"

a valid comparison of the two quotes requires escaping the active quote, or using the alternate quote that doesn't require escaping

These are all 098f6bcd4621d373cade4e832627b4f6


    resty -e "ngx.say(ngx.md5('test'))"
    resty -e 'ngx.say(ngx.md5("test"))'
    resty -e "ngx.say(ngx.md5(\"test\"))"             
    resty -e 'ngx.say(ngx.md5(\'test\'))'

These are all d41d8cd98f00b204e9800998ecf8427e

    resty -e "ngx.say(ngx.md5(''))"
    resty -e 'ngx.say(ngx.md5(""))'
    resty -e "ngx.say(ngx.md5(\"\"))"             

this is invalid in bash:

    resty -e 'ngx.say(ngx.md5(\'\'))'

Igor Clark

unread,
Apr 2, 2021, 7:42:13 AM4/2/21
to openre...@googlegroups.com
Bravo. Eagle-eyed work there!!

👏 

On 1 Apr 2021, at 18:37, 'jona...@findmeon.com' via openresty-en <openre...@googlegroups.com> wrote:

`d41d8cd98f00b204e9800998ecf8427e` is the md5 of an empty string, which caught my eye.
--
You received this message because you are subscribed to the Google Groups "openresty-en" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openresty-en...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/openresty-en/97e20c2c-2b67-4bf4-8c9c-d6852024a460n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages