From c8adc31b752e35d3d2c297f88bd313d1ba508d42 Mon Sep 17 00:00:00 2001 From: cenfun Date: Wed, 5 Jun 2024 23:25:19 +0800 Subject: [PATCH] replace build-in sha1 with md5 --- js/custom-nodes-manager.js | 51 ++++++++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 7 deletions(-) diff --git a/js/custom-nodes-manager.js b/js/custom-nodes-manager.js index 224f9ab1..91f282cf 100644 --- a/js/custom-nodes-manager.js +++ b/js/custom-nodes-manager.js @@ -1394,11 +1394,48 @@ export class CustomNodesManager { async function calculateHash(item) { const message = item.title + item.files[0]; - const encoder = new TextEncoder(); - const data = encoder.encode(message); - const hashBuffer = await window.crypto.subtle.digest("SHA-1", data); - const hashArray = Array.from(new Uint8Array(hashBuffer)); - const hashHex = hashArray.map((b) => b.toString(16).padStart(2, "0")).join(""); - return hashHex; + return md5(message); } - \ No newline at end of file + +function md5(inputString) { + const hc = '0123456789abcdef'; + const rh = n => {let j,s='';for(j=0;j<=3;j++) s+=hc.charAt((n>>(j*8+4))&0x0F)+hc.charAt((n>>(j*8))&0x0F);return s;} + const ad = (x,y) => {let l=(x&0xFFFF)+(y&0xFFFF);let m=(x>>16)+(y>>16)+(l>>16);return (m<<16)|(l&0xFFFF);} + const rl = (n,c) => (n<>>(32-c)); + const cm = (q,a,b,x,s,t) => ad(rl(ad(ad(a,q),ad(x,t)),s),b); + const ff = (a,b,c,d,x,s,t) => cm((b&c)|((~b)&d),a,b,x,s,t); + const gg = (a,b,c,d,x,s,t) => cm((b&d)|(c&(~d)),a,b,x,s,t); + const hh = (a,b,c,d,x,s,t) => cm(b^c^d,a,b,x,s,t); + const ii = (a,b,c,d,x,s,t) => cm(c^(b|(~d)),a,b,x,s,t); + const sb = x => { + let i;const nblk=((x.length+8)>>6)+1;const blks=[];for(i=0;i>2]|=x.charCodeAt(i)<<((i%4)*8);} + blks[i>>2]|=0x80<<((i%4)*8);blks[nblk*16-2]=x.length*8;return blks; + } + let i,x=sb(inputString),a=1732584193,b=-271733879,c=-1732584194,d=271733878,olda,oldb,oldc,oldd; + for(i=0;i