utils_crypto_encode-hex.ts

import "fastestsmallesttextencoderdecoder/EncoderDecoderTogether.min.js";

/**
 * 문자열을 16진수로 변환
 *
 * @param {string} str  - 변환할 문자열
 * @returns {string} 16진수 문자열
 * @example
 * encodeHex("Hello"); // "48656c6c6f"
 *
 */
export function encodeHex(str: string): string {
    const encoder = new TextEncoder();
    const utf8Bytes = encoder.encode(str);

    return Array.from(utf8Bytes)
        .map((byte) => byte.toString(16).padStart(2, "0"))
        .join("");
}