함수 md5()


1 Bash[ | ]

echo -n '' | md5sum  # d41d8cd98f00b204e9800998ecf8427e  -
echo -n 'hello world' | md5sum  # 5eb63bbbe01eeed093cb22bb8f5acdc3  -
 echo -n 'hello world' | md5sum | cut -f1 -d' '  # 5eb63bbbe01eeed093cb22bb8f5acdc3
a='hello world'
b=`echo -n $a | md5sum | cut -f1 -d' '`
echo $b  # 5eb63bbbe01eeed093cb22bb8f5acdc3

2 Java[ | ]

public class MyClass {
    static String md5(String s) {
        java.security.MessageDigest md;
        try { md = java.security.MessageDigest.getInstance("MD5"); }
        catch (Exception e) { return null; }
        md.update(s.getBytes());
        String result = (new java.math.BigInteger(1, md.digest())).toString(16);
        while(result.length()<32) { result = "0" + result; }
        return result;
    }
    public static void main(String args[]) {
        System.out.println(md5(""));             // d41d8cd98f00b204e9800998ecf8427e
        System.out.println(md5("hello33"));      // 005529451481309d2b8f708bbb81ea41
        System.out.println(md5("hello world"));  // 5eb63bbbe01eeed093cb22bb8f5acdc3
    }
}

3 JavaScript[ | ]

<script src="//cdnjs.cloudflare.com/ajax/libs/blueimp-md5/2.10.0/js/md5.min.js"></script>
<script>
var hash = md5("Message");
console.log(hash);  // 4c2a8fe7eaf24721cc7a9f0175115bd4 
</script>

4 PHP[ | ]

echo md5('')           ."\n";  # d41d8cd98f00b204e9800998ecf8427e
echo md5('hello33')    ."\n";  # 005529451481309d2b8f708bbb81ea41
echo md5('hello world')."\n";  # 5eb63bbbe01eeed093cb22bb8f5acdc3
echo hash('md5','')           ."\n";  # d41d8cd98f00b204e9800998ecf8427e
echo hash('md5','hello33')    ."\n";  # 005529451481309d2b8f708bbb81ea41
echo hash('md5','hello world')."\n";  # 5eb63bbbe01eeed093cb22bb8f5acdc3

5 Python[ | ]

import hashlib
print( hashlib.md5('hello world'.encode('utf-8')).hexdigest() )  # 5eb63bbbe01eeed093cb22bb8f5acdc3

6 Perl[ | ]

use Digest::MD5 qw(md5_hex);
print md5_hex('hello world');  # 5eb63bbbe01eeed093cb22bb8f5acdc3

7 같이 보기[ | ]

8 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}