"함수 md5()"의 두 판 사이의 차이

 
(사용자 3명의 중간 판 44개는 보이지 않습니다)
1번째 줄: 1번째 줄:
[[category: String]]
[[category: String]]
==Bash==
[[category: Bash]]
<syntaxhighlight lang='bash' run>
echo -n '' | md5sum  # d41d8cd98f00b204e9800998ecf8427e  -
</syntaxhighlight>
<syntaxhighlight lang='bash' run>
echo -n 'hello world' | md5sum  # 5eb63bbbe01eeed093cb22bb8f5acdc3  -
</syntaxhighlight>
<syntaxhighlight lang='bash' run> echo -n 'hello world' | md5sum | cut -f1 -d' '  # 5eb63bbbe01eeed093cb22bb8f5acdc3
</syntaxhighlight>
<syntaxhighlight lang='bash' run>
a='hello world'
b=`echo -n $a | md5sum | cut -f1 -d' '`
echo $b  # 5eb63bbbe01eeed093cb22bb8f5acdc3
</syntaxhighlight>
==Java==
[[분류: Java]]
{{참고|자바 md5()}}
<syntaxhighlight lang='java' run>
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
    }
}
</syntaxhighlight>


==JavaScript==
==JavaScript==
{{참고|자바스크립트 md5()}}
[[category:JavaScript]]
[[category:JavaScript]]
<source lang='html5'>
<syntaxhighlight lang='html' run outheight='0'>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/md5.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/blueimp-md5/2.10.0/js/md5.min.js"></script>
<script>
    var hash = CryptoJS.MD5("Message");
</script>
</source>
<source lang='html5'>
<script src="http://rawgithub.com/kvz/phpjs/master/functions/xml/utf8_encode.js"></script>
<script src="http://rawgithub.com/kvz/phpjs/master/functions/strings/md5.js"></script>
<script>
<script>
document.write( md5('jmnote.com') );
var hash = md5("Message");
// 905c088159f7584be751a1bb7042a9ea
console.log(hash); // 4c2a8fe7eaf24721cc7a9f0175115bd4
</script>
</script>
</source>
</syntaxhighlight>
*http://phpjs.org/functions/md5/


==PHP==
==PHP==
{{참고|PHP md5()}}
[[category:PHP]]
[[category:PHP]]
<source lang='php'>
<syntaxhighlight lang='php' run>
$hash = md5("Message");
echo md5('')          ."\n";  # d41d8cd98f00b204e9800998ecf8427e
</source>
echo md5('hello33')    ."\n";  # 005529451481309d2b8f708bbb81ea41
<source lang='php'>
echo md5('hello world')."\n"; # 5eb63bbbe01eeed093cb22bb8f5acdc3
echo md5('jmnote.com');
</syntaxhighlight>
// 905c088159f7584be751a1bb7042a9ea
<syntaxhighlight lang='php' run>
</source>
echo hash('md5','')          ."\n";  # d41d8cd98f00b204e9800998ecf8427e
echo hash('md5','hello33')    ."\n";  # 005529451481309d2b8f708bbb81ea41
echo hash('md5','hello world')."\n"; # 5eb63bbbe01eeed093cb22bb8f5acdc3
</syntaxhighlight>
 
==Python==
[[category: Python]]
{{참고|파이썬 md5()}}
<syntaxhighlight lang='Python' run>
import hashlib
print( hashlib.md5('hello world'.encode('utf-8')).hexdigest() )  # 5eb63bbbe01eeed093cb22bb8f5acdc3
</syntaxhighlight>
 
==Perl==
[[category: Perl]]
<syntaxhighlight lang='perl' run>
use Digest::MD5 qw(md5_hex);
print md5_hex('hello world');  # 5eb63bbbe01eeed093cb22bb8f5acdc3
</syntaxhighlight>


==같이 보기==
==같이 보기==
*[[MD5]]
* [[MD5]]
*[[utf8_encode]]
* [[리눅스 md5sum]]
* [[함수 sha256()]]
* [[함수 crypt()]]
* [[함수 str2rgb()]]


==참고 자료==
==참고==
*http://eqcode.com/wiki/md5
*http://eqcode.com/wiki/md5

2021년 4월 14일 (수) 21:33 기준 최신판


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 }}