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

 
(사용자 2명의 중간 판 9개는 보이지 않습니다)
3번째 줄: 3번째 줄:
==Bash==
==Bash==
[[category: Bash]]
[[category: Bash]]
<source lang='bash'>
<syntaxhighlight lang='bash' run>
echo -n '' | md5sum
echo -n '' | md5sum # d41d8cd98f00b204e9800998ecf8427e  -
# d41d8cd98f00b204e9800998ecf8427e  -
</syntaxhighlight>
</source>
<syntaxhighlight lang='bash' run>
<source lang='bash'>
echo -n 'hello world' | md5sum # 5eb63bbbe01eeed093cb22bb8f5acdc3  -
echo -n 'hello world' | md5sum
</syntaxhighlight>
# 5eb63bbbe01eeed093cb22bb8f5acdc3  -
<syntaxhighlight lang='bash' run> echo -n 'hello world' | md5sum | cut -f1 -d' ' # 5eb63bbbe01eeed093cb22bb8f5acdc3
</source>
</syntaxhighlight>
<source lang='bash'>
<syntaxhighlight lang='bash' run>
echo -n 'hello world' | md5sum | cut -f1 -d' '
# 5eb63bbbe01eeed093cb22bb8f5acdc3
</source>
<source lang='bash'>
a='hello world'
a='hello world'
b=`echo -n $a | md5sum | cut -f1 -d' '`
b=`echo -n $a | md5sum | cut -f1 -d' '`
echo $b
echo $b # 5eb63bbbe01eeed093cb22bb8f5acdc3
# 5eb63bbbe01eeed093cb22bb8f5acdc3
</syntaxhighlight>
</source>


==Java==
==Java==
[[분류: Java]]
[[분류: Java]]
{{참고|자바 md5()}}
{{참고|자바 md5()}}
<source lang='java'>
<syntaxhighlight lang='java' run>
public class MyClass {
public class MyClass {
     static String md5(String s) {
     static String md5(String s) {
37번째 줄: 32번째 줄:
     }
     }
     public static void main(String args[]) {
     public static void main(String args[]) {
         System.out.println(md5(""));
         System.out.println(md5(""));             // d41d8cd98f00b204e9800998ecf8427e
        // d41d8cd98f00b204e9800998ecf8427e
         System.out.println(md5("hello33"));     // 005529451481309d2b8f708bbb81ea41
         System.out.println(md5("hello33"));
         System.out.println(md5("hello world")); // 5eb63bbbe01eeed093cb22bb8f5acdc3
        // 005529451481309d2b8f708bbb81ea41
         System.out.println(md5("hello world"));
        // 5eb63bbbe01eeed093cb22bb8f5acdc3
     }
     }
}
}
</source>
</syntaxhighlight>


==JavaScript==
==JavaScript==
{{참고|자바스크립트 md5()}}
{{참고|자바스크립트 md5()}}
[[category:JavaScript]]
[[category:JavaScript]]
<source lang='html'>
<syntaxhighlight lang='html' run outheight='0'>
<script src="//cdnjs.cloudflare.com/ajax/libs/blueimp-md5/2.10.0/js/md5.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/blueimp-md5/2.10.0/js/md5.min.js"></script>
<script>
<script>
var hash = md5("Message");
var hash = md5("Message");
console.log(hash);  // 4c2a8fe7eaf24721cc7a9f0175115bd4
</script>
</script>
</source>
</syntaxhighlight>


==PHP==
==PHP==
{{참고|PHP md5()}}
{{참고|PHP md5()}}
[[category:PHP]]
[[category:PHP]]
<source lang='php'>
<syntaxhighlight lang='php' run>
echo md5('');
echo md5('')           ."\n"; # d41d8cd98f00b204e9800998ecf8427e
# d41d8cd98f00b204e9800998ecf8427e
echo md5('hello33')   ."\n"; # 005529451481309d2b8f708bbb81ea41
echo md5('hello33');
echo md5('hello world')."\n"; # 5eb63bbbe01eeed093cb22bb8f5acdc3
# 005529451481309d2b8f708bbb81ea41
</syntaxhighlight>
echo md5('hello world');
<syntaxhighlight lang='php' run>
# 5eb63bbbe01eeed093cb22bb8f5acdc3
echo hash('md5','')           ."\n"; # d41d8cd98f00b204e9800998ecf8427e
</source>
echo hash('md5','hello33')   ."\n"; # 005529451481309d2b8f708bbb81ea41
<source lang='php'>
echo hash('md5','hello world')."\n"; # 5eb63bbbe01eeed093cb22bb8f5acdc3
echo hash('md5','');
</syntaxhighlight>
# d41d8cd98f00b204e9800998ecf8427e
echo hash('md5','hello33');
# 005529451481309d2b8f708bbb81ea41
echo hash('md5','hello world');
# 5eb63bbbe01eeed093cb22bb8f5acdc3
</source>


==Python==
==Python==
[[category: Python]]
[[category: Python]]
{{참고|파이썬 md5()}}
{{참고|파이썬 md5()}}
<source lang='Python'>
<syntaxhighlight lang='Python' run>
import hashlib
import hashlib
print( hashlib.md5('hello world'.encode('utf-8')).hexdigest() )
print( hashlib.md5('hello world'.encode('utf-8')).hexdigest() ) # 5eb63bbbe01eeed093cb22bb8f5acdc3
# 5eb63bbbe01eeed093cb22bb8f5acdc3
</syntaxhighlight>
</source>


==Perl==
==Perl==
[[category: Perl]]
[[category: Perl]]
<source lang='perl'>
<syntaxhighlight lang='perl' run>
use Digest::MD5 qw(md5_hex);
use Digest::MD5 qw(md5_hex);
print md5_hex('hello world');
print md5_hex('hello world'); # 5eb63bbbe01eeed093cb22bb8f5acdc3
# 5eb63bbbe01eeed093cb22bb8f5acdc3
</syntaxhighlight>
</source>


==같이 보기==
==같이 보기==

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