Programming

(C#) MD5 hash

steloflute 2014. 4. 17. 23:19

http://blogs.msdn.com/b/csharpfaq/archive/2006/10/09/how-do-i-calculate-a-md5-hash-from-a-string_3f00_.aspx

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1 {
    class Program {
        public static string md5(string input) {
            // step 1, calculate MD5 hash from input
            var md5 = System.Security.Cryptography.MD5.Create();
            var inputBytes = System.Text.Encoding.ASCII.GetBytes(input);
            var hash = md5.ComputeHash(inputBytes);

            // step 2, convert byte array to hex string
            var sb = new StringBuilder();
            foreach (var b in hash) {
                sb.Append(b.ToString("x2"));
            }
            return sb.ToString();
        }

        static void Main(string[] args) {
            Console.WriteLine(md5("hello"));
            Console.ReadKey();
        }
    }
}

 

http://hilite.me/

Calculate MD5 checksum for a file

 

'Programming' 카테고리의 다른 글

(Perl) HTTP::Tiny  (0) 2014.04.25
(Emacs) cider 설치  (0) 2014.04.23
Parenj, Paren#이 이제 thread를 지원합니다.  (0) 2014.04.14
[C++] Thread(쓰레드, 스레드)  (0) 2014.04.13
(Go) channel  (0) 2014.04.13