Implement util function to generate hash string
This commit is contained in:
parent
85d462a53d
commit
ba8a7cd6ef
@ -8,6 +8,14 @@
|
|||||||
* Learn more at https://developers.cloudflare.com/workers/
|
* 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 {
|
export default {
|
||||||
async fetch(request, env, ctx) {
|
async fetch(request, env, ctx) {
|
||||||
return new Response('Hello World!');
|
return new Response('Hello World!');
|
||||||
|
Loading…
Reference in New Issue
Block a user