Hashing

No Authentication

Client

Server

DB

정보 요청 Get/ email

Response/ email, phone number, etc ...

Authentication ( Plaintext )

Client

Server

DB

Response/ email, phone number, etc ...

email: asdf@gmail.com
password: asdfasdf

email: asdf@gmail.com
password: asdfasdf

비교

asdf@gmail.com 의

phone_number, address, etc ... 요청

Encryption

암호화는 일련의 정보를 임의의 방식을 사용하여 다른 형태로 변환하여 

해당 방식에 대한 정보를 소유한 사람을 제외하고 이해할 수 없도록 

'알고리즘'을 이용해 정보를 전달하는 과정

Encryption: 예

shiftBy('bicycle', 2) // => 'dkezeng'
shiftBy('dkezeng', -2) // => 'bicycle'

Encryption: 예

shiftBy('bicycle', 2) // => 'dkezeng'
shiftBy('dkezeng', -2) // => 'bicycle'

const shiftBy = function(content, offset) {
    return content.split('').map(function(letter) {
        return String.fromCharCode(letter.charCodeAt() + offset);
    }).join('');
};

넘긴 수만큼 위치가 바뀐 알파벳 반환

shiftBy('a', 2) => abcd ... => 'c'

Authentication ( Encryption )

Client

Server

DB

Response/ email, phone number, etc ...

email: asdf@gmail.com
password: asdfasdf

email: asdf@gmail.com
password: cufhcufh

비교

asdf@gmail.com 의

phone_number, address, etc ... 요청

password 암호화

'asdfasdf'    ========>  'cufhcufh'

Hashing

어떠한 문자열에 '임의의 연산'을 적용하여 다른 문자열로 변환하는 것 

1. 모든 값에 대해 해시 값을 계산하는데 오래걸리지 않아야한다

2. 최대한 해시 값을 피해야하며, 모든 값은 고유한 해시 값을 가진다

3. 아주 작은 단위의 변경 이라도 완전히 다른 해시 값을 가져야 한다

Authentication ( Hashing )

Client

Server

DB

Response/ email, phone number, etc ...

email: asdf@gmail.com
password: asdfasdf

email: asdf@gmail.com
password: 0g7s80a...

비교

asdf@gmail.com 의

phone_number, address, etc ... 요청

password 암호화

'asdfasdf'    ===hashing==>  '0g7s80a...'

Salt

해시 하려는 값(원본)에 추가하는 값

1. 암호화를 진행했다면 '해당 알고리즘을 알고있는 순간' 바로 원본을 얻어낼 수 있다.

2. 원본값에 임의로 약속된 추가 문자열을 추가하여 해시를 진행하여 기존 해시값과
    전혀 다른 해시 값이 반환되어 알고리즘이 노출 되더라도 원본 값을 보호할 수 있도록
    하는 안전장치

3.  기존 : (암호화 하려는 값) => (hash값)

     Salt 사용 : (암호화 하려는 값) + (Salt 용 값) => (hash값)

Salt

Client

Server

DB

Response/ email, phone number, etc ...

email: asdf@gmail.com
password: asdfasdf

email: asdf@gmail.com
salt: 'test'
password: 0g7s80a...

비교

asdf@gmail.com 의

phone_number, address, etc ... 요청

password 암호화

'asdfasdf'    === hashing + 'test' ==>  '0g7s80a...'

Crypto ( NodeJS )

Node JS 내장 암호화 모듈

( https://nodejs.org/api/crypto.html )

const crypto = require('crypto');

const secret = 'abcdefg';
const hash = crypto.createHmac('sha256', secret)
                   .update('I love cupcakes')
                   .digest('hex');
console.log(hash);
// Prints:
//   c0fa1bc00531bd78ef38c628449c5102aeabd49b5dc3a2a516ea6ea959d6658e

Crypto ( NodeJS )

const crypto = require('crypto');

const secret = 'abcdefg';
const hash = crypto.createHmac('sha256', secret)
                   .update('I love cupcakes')
                   .digest('hex');
console.log(hash);
// Prints:
//   c0fa1bc00531bd78ef38c628449c5102aeabd49b5dc3a2a516ea6ea959d6658e

 알고리즘 방식

Salt

Hashing 할 값

인코딩 방식

값 + Salt => 알고리즘으로 값 변환 => 변환 값을 입력 받은 방식으로 인코딩 => Hash 값

Shortly Express - hashing

By Codestates

Shortly Express - hashing

  • 675