노출되는 이미지가 불편하시겠지만 양해를 구합니다. 노출, 클릭등에 관한 자료로 활용 중입니다.

SHA-256 해시(Hash) 이해

 

# SHA-256 Hash Calculator(계산기)를 통한 변환

 

# 해시(Hash)?

많은 용량의 데이타를 고정된 크기의 고유값으로 만드는 것이다. 데이타 값이 약간만 달려져도 해시에는 예측할 수 없는 큰 변화가 발행하며 전형 다른 값이 되며, 이를 일명 눈사태 효과라고 부른다.

 

# HMAC(해시 메시지 인증 코드)?

해시는 데이터의 수정 또는 변경은 검출 할 수 있으나, 거짓 행세는 찾을 수 없기 때문에

인증이 필요해 진다.

 

송신자와 수신자만이 공유하고 있는 Key와 Data(메시지)를 혼합해서 해시값을 만드는 것이다. 이를 HMAC(Hash-based Message Authentication Code)이라고 한다.

 

 

SHA-256 ?

Secure Hash Algorithm(SHA)-256약자의 조합으로 생성된 고유의 값이 256비트이다. ( 하지만, SHA-1은 1비트가 아니고, ver.1을 뜻한다. )

SHA-2기반으로 SHA-224, SHA-256,SHA-384, SHA-512가 만들어 졌다. ( 뒤에 숫자는 비트수를 의미한다. )

SHA-1(160비트)은 2008년에 보안에 심각한 결함이 발견

 

 

# 해쉬함수별 출력값(해쉬값) 길이 비교

Hash 함수

출력값 길이

16진수

md5

128 bits

32 bytes

ex) 8380482228e75045a7d14e063bde014b

sha-1

160 bits

40 bytes

ex) 764C46AE8BC50C4823E50F18DA45B9A21E8DD10B

sha-256

256 bits

64 bytes

ex) be178c0543eb17f5f3043021c9e5fcf30285e557a4fc309cce97ff9ca6182912


 

# 참조 :

http://sunphiz.me/wp/archives/1104?ckattempt=1

http://www.xorbin.com/tools/sha256-hash-calculator

https://www.jokecamp.com/blog/examples-of-creating-base64-hashes-using-hmac-sha256-in-different-languages/

 

 

# Message Digest 만들기

StringBuffer hexString = new StringBuffer();
MessageDigest md = MessageDigest.getInstance("SHA-256");
byte[] hash = md.digest();

for (int i = 0; i < hash.length; i++) {
    if ((0xff & hash[i]) < 0x10) {
        hexString.append("0"
                + Integer.toHexString((0xFF & hash[i])));
    } else {
        hexString.append(Integer.toHexString(0xFF & hash[i]));
    }
}

 

출처 : https://stackoverflow.com/questions/5470219/get-md5-string-from-message-digest

블로그 이미지

StartGuide

I want to share the basic to programming of each category and how to solve the error. This basic instruction can be extended further. And I have been worked in southeast Asia more than 3 years. And I want to have the chance to work another country.

,