找回密码
 立即注册

QQ登录

只需一步,快速开始

lucaswang
初级会员   /  发表于:2022-9-21 17:00  /   查看:1168  /  回复:3
5金币
我们一个网站的签名需要SHA256加密,请问有这方面的插件吗?或者用其他什么方法可以实现吗,有偿求助。

3 个回复

倒序浏览
最佳答案
最佳答案
桂花酒酿丸子悬赏达人认证 活字格认证
高级会员   /  发表于:2022-9-21 17:00:30
来自 3#

  1. class SHA256 {
  2.     constructor(data) {
  3.         this.K256 = new Array(
  4.             0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  5.             0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  6.             0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  7.             0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  8.             0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  9.             0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  10.             0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  11.             0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  12.             0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  13.             0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  14.             0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  15.             0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  16.             0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  17.             0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  18.             0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  19.             0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
  20.         );

  21.         this.sha256_hex_digits = "0123456789abcdef";

  22.         this.ihash = [0x6a09e667,
  23.             0xbb67ae85,
  24.             0x3c6ef372,
  25.             0xa54ff53a,
  26.             0x510e527f,
  27.             0x9b05688c,
  28.             0x1f83d9ab,
  29.             0x5be0cd19];
  30.         this.count = [0, 0];
  31.         this.buffer = new Array(64);

  32.         this.sha256_update(data, data.length);
  33.         this.sha256_final();
  34.     }

  35.      rotateRight(n, x) {
  36.         return ((x >>> n) | (x << (32 - n)));
  37.     }
  38.     choice(x, y, z) {
  39.         return ((x & y) ^ (~x & z));
  40.     }
  41.     majority(x, y, z) {
  42.         return ((x & y) ^ (x & z) ^ (y & z));
  43.     }
  44.     sha256_Sigma0(x) {
  45.         return (this.rotateRight(2, x) ^ this.rotateRight(13, x) ^ this.rotateRight(22, x));
  46.     }
  47.     sha256_Sigma1(x) {
  48.         return (this.rotateRight(6, x) ^ this.rotateRight(11, x) ^ this.rotateRight(25, x));
  49.     }
  50.     sha256_sigma0(x) {
  51.         return (this.rotateRight(7, x) ^ this.rotateRight(18, x) ^ (x >>> 3));
  52.     }
  53.     sha256_sigma1(x) {
  54.         return (this.rotateRight(17, x) ^ this.rotateRight(19, x) ^ (x >>> 10));
  55.     }
  56.     sha256_expand(W, j) {
  57.         return (W[j & 0x0f] += this.sha256_sigma1(W[(j + 14) & 0x0f]) + W[(j + 9) & 0x0f] +
  58.             this.sha256_sigma0(W[(j + 1) & 0x0f]));
  59.     }


  60.     safe_add(x, y) {
  61.         let lsw = (x & 0xffff) + (y & 0xffff);
  62.         let msw = (x >> 16) + (y >> 16) + (lsw >> 16);
  63.         return (msw << 16) | (lsw & 0xffff);
  64.     }


  65.     sha256_transform() {
  66.         let a, b, c, d, e, f, g, h, T1, T2;
  67.         let W = new Array(16);

  68.         a = this.ihash[0];
  69.         b = this.ihash[1];
  70.         c = this.ihash[2];
  71.         d = this.ihash[3];
  72.         e = this.ihash[4];
  73.         f = this.ihash[5];
  74.         g = this.ihash[6];
  75.         h = this.ihash[7];

  76.         for (let i = 0; i < 16; i++)
  77.             W[i] = ((this.buffer[(i << 2) + 3]) | (this.buffer[(i << 2) + 2] << 8) | (this.buffer[(i << 2) + 1]
  78.                 << 16) | (this.buffer[i << 2] << 24));

  79.         for (let j = 0; j < 64; j++) {
  80.             T1 = h + this.sha256_Sigma1(e) + this.choice(e, f, g) + this.K256[j];
  81.             if (j < 16) T1 += W[j];
  82.             else T1 += this.sha256_expand(W, j);
  83.             T2 = this.sha256_Sigma0(a) + this.majority(a, b, c);
  84.             h = g;
  85.             g = f;
  86.             f = e;
  87.             e = this.safe_add(d, T1);
  88.             d = c;
  89.             c = b;
  90.             b = a;
  91.             a = this.safe_add(T1, T2);
  92.         }

  93.         this.ihash[0] += a;
  94.         this.ihash[1] += b;
  95.         this.ihash[2] += c;
  96.         this.ihash[3] += d;
  97.         this.ihash[4] += e;
  98.         this.ihash[5] += f;
  99.         this.ihash[6] += g;
  100.         this.ihash[7] += h;
  101.     }

  102.     sha256_update(data, inputLen) {
  103.         let i, index, curpos = 0;
  104.         index = ((this.count[0] >> 3) & 0x3f);
  105.         let remainder = (inputLen & 0x3f);

  106.         if ((this.count[0] += (inputLen << 3)) < (inputLen << 3)) this.count[1]++;
  107.         this.count[1] += (inputLen >> 29);

  108.         for (i = 0; i + 63 < inputLen; i += 64) {
  109.             for (let j = index; j < 64; j++)
  110.                 this.buffer[j] = data.charCodeAt(curpos++);
  111.             this.sha256_transform();
  112.             index = 0;
  113.         }

  114.         for (let j = 0; j < remainder; j++) {
  115.             this.buffer[j] = data.charCodeAt(curpos++);
  116.         }
  117.     }

  118.     sha256_final() {
  119.         let index = ((this.count[0] >> 3) & 0x3f);
  120.         this.buffer[index++] = 0x80;
  121.         if (index <= 56) {
  122.             for (let i = index; i < 56; i++)
  123.                 this.buffer[i] = 0;
  124.         } else {
  125.             for (let i = index; i < 64; i++)
  126.                 this.buffer[i] = 0;
  127.             this.sha256_transform();
  128.             for (let i = 0; i < 56; i++)
  129.                 this.buffer[i] = 0;
  130.         }
  131.         this.buffer[56] = (this.count[1] >>> 24) & 0xff;
  132.         this.buffer[57] = (this.count[1] >>> 16) & 0xff;
  133.         this.buffer[58] = (this.count[1] >>> 8) & 0xff;
  134.         this.buffer[59] = this.count[1] & 0xff;
  135.         this.buffer[60] = (this.count[0] >>> 24) & 0xff;
  136.         this.buffer[61] = (this.count[0] >>> 16) & 0xff;
  137.         this.buffer[62] = (this.count[0] >>> 8) & 0xff;
  138.         this.buffer[63] = this.count[0] & 0xff;
  139.         this.sha256_transform();
  140.     }

  141.     sha256_encode_bytes() {
  142.         let j = 0;
  143.         let output = new Array(32);
  144.         for (let i = 0; i < 8; i++) {
  145.             output[j++] = ((this.ihash[i] >>> 24) & 0xff);
  146.             output[j++] = ((this.ihash[i] >>> 16) & 0xff);
  147.             output[j++] = ((this.ihash[i] >>> 8) & 0xff);
  148.             output[j++] = (this.ihash[i] & 0xff);
  149.         }
  150.         return output;
  151.     }

  152.     toHex() {
  153.         let output = new String();
  154.         for (let i = 0; i < 8; i++) {
  155.             for (let j = 28; j >= 0; j -= 4)
  156.                 output += this.sha256_hex_digits.charAt((this.ihash[i] >>> j) & 0x0f);
  157.         }
  158.         return output;
  159.     }

  160. }

  161. var str = Forguncy.Page.getCell("str").getValue();
  162. var outvar = new SHA256(str).toHex();
  163. Forguncy.Page.getCell("out").setValue(outvar)
复制代码


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复 使用道具 举报
wangpenga悬赏达人认证
银牌会员   /  发表于:2022-9-21 17:12:23
2#
本帖最后由 wangpenga 于 2022-9-21 17:17 编辑

如何生成SHA256签名
https://gcdn.grapecity.com.cn/fo ... 99505&fromuid=63460
(出处: 葡萄城产品技术社区)



活字格内JS实现AES加密解密
https://gcdn.grapecity.com.cn/fo ... 6&fromuid=63460
(出处: 葡萄城产品技术社区)



回复 使用道具 举报
David.Zhong讲师达人认证 悬赏达人认证 活字格认证
论坛元老   /  发表于:2022-9-21 17:33:05
4#
感谢大佬的支持~
如果您的问题已解决,请及时设置最佳答案给有帮助到你的回复哟~
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部