Wiki_JS_Hash - inoueshinichi/Wiki_Web GitHub Wiki
ハッシュ値の作成
ユーザー用ハッシュ
- DBでパスワードの代替値として使用する
- salt(ソルト) : アプリ固有の値
- パスワード
function getHash(passwd: string) {
const salt = '::EVuCM0QwfI48Krpr' // ソルト
const crypto = require('node:crypto');
const hashsum = crypto.createHash('sha512');
hashsum.update(passwd + salt);
return hashsum.digest('hex');
}
アクセス(認可)トークンの作成
- 各APIへの認可用トークン
- ユーザID
- タイムスタンプ
- ソルト
function getAuthToken(userid: string) {
const timestamp: number = (new Date()).getTime();
return getHash(`${userid}:${timestamp}`);
}
- ハッシュ値を作成する際にソルトを混ぜることでハッシュ値からパスワードを類推できないようにする.
SHAハッシュ関数
- Secure Hash Algorithm
- 米国立標準技術研究所(NIST)によって標準ハッシュ関数に指定されている方式
- ハッシュの用途・・・暗号化、改竄検出、データ破損検出