@bcsdlab/utils
Version:
bcsdlab 프론트엔드 유틸 모음입니다.
16 lines (12 loc) • 517 B
text/typescript
/** sha256 암호화를 거쳐 해싱된 값을 제공합니다. */
export async function sha256(message: string) {
// encode as UTF-8
const msgBuffer = new TextEncoder().encode(message);
// hash the message
const hashBuffer = await crypto.subtle.digest('SHA-256', msgBuffer);
// convert ArrayBuffer to Array
const hashArray = Array.from(new Uint8Array(hashBuffer));
// convert bytes to hex string
const hashHex = hashArray.map((b) => b.toString(16).padStart(2, '0')).join('');
return hashHex;
}