diff --git a/src/index.js b/src/index.js index de66b62..8b93fed 100644 --- a/src/index.js +++ b/src/index.js @@ -8,6 +8,14 @@ * Learn more at https://developers.cloudflare.com/workers/ */ +async function getHashString(string, method = 'SHA-256') { + const encoder = new TextEncoder(); + const data = encoder.encode(string); + const hash = await crypto.subtle.digest(method, data); + const hashArray = Array.from(new Uint8Array(hash)); + return hashArray.map(b => b.toString(16).padStart(2, '0')).join(''); +} + export default { async fetch(request, env, ctx) { return new Response('Hello World!');