fullstack.web/swa/u/gmhelper.js

2 lines
45 KiB
JavaScript
Raw Permalink Normal View History

!function(t,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?exports.gmhelper=r():t.gmhelper=r()}("undefined"!=typeof self?self:this,(function(){return t={10:(t,r,e)=>{const i=e(694),{G:n,curve:o,n:s}=i.generateEcparam(),h=e(664).sm3,u=e(742),a=e(751);function f(t){for(var r="",e=0;e<t.length;e++){var i=t.charCodeAt(e).toString(16);i.length<2&&(i="0"+i),r+=i}return r}function c(t,r,e){if(32!==t.length||32!==r.length||32!==e.length)throw"输入格式错误";for(var i=l(t),n=l(r),o=l(e),s=[],h=0;h<16;h++)s[h]=i[h]^n[h]^o[h];return function(t){for(var r=[],e=0;e<t.length;e++)r.push((t[e]>>>4).toString(16)),r.push((15&t[e]).toString(16));return r.join("")}(s)}function l(t){for(var r=[],e=0;e<t.length;e+=2)r.push(parseInt(t.substr(e,2),16));return r}function p(t,r,e){var i=c(t,r,e),n=a.SM4CryptECB("00000000000000000000000000000000",1,i);return{checkValue:n.slice(0,8),ret:n,keyPlaintext:i}}function g(t){return a.SM4CryptECB("00000000000000000000000000000000",1,t)}function f(t){for(var r="",e=0;e<t.length;e++){var i=t.charCodeAt(e).toString(16);i.length<2&&(i="0"+i),r+=i}return r}function y(t,r,e="1234567812345678"){e=i.utf8ToHex(e);const o=i.leftPad(n.curve.a.toBigInteger().toRadix(16),64),s=i.leftPad(n.curve.b.toBigInteger().toRadix(16),64),u=i.leftPad(n.getX().toBigInteger().toRadix(16),64),a=i.leftPad(n.getY().toBigInteger().toRadix(16),64);let c,l;if(128===r.length)c=r.substr(0,64),l=r.substr(64,64);else{const t=n.curve.decodePointHex(r);c=i.leftPad(t.getX().toBigInteger().toRadix(16),64),l=i.leftPad(t.getY().toBigInteger().toRadix(16),64)}const p=i.hexToArray(e+o+s+u+a+c+l),g=4*e.length;p.unshift(255&g),p.unshift(g>>8&255);const y=h(p);return{z:y,hex:h(i.hexToArray(y+f(t)))}}function d(t){return t=(t=t.substr("-----BEGIN ECDSA PUBLIC KEY-----".length)).substr(0,t.length-"-----END ECDSA PUBLIC KEY-----".length),(t=function(t){for(var r="",e=0;e<t.length;e++){var i=t[e];r+=1===(i=i.toString(16)).length?"0"+i:i}return r}(u.toByteArray(t))).substr(t.indexOf("03420004")+8)}t.exports={xor:c,kcv:g,decryptKey:function(t,r){return a.SM4CryptECB(t,0,r)},checkValue:p,checkValueKey:function(t,r,e,i){const n=c(t,r,e);var o=a.SM4CryptECB("00000000000000000000000000000000",1,n);const s=o.slice(0,8);return{keyCiphertext:a.SM4CryptECB(n,1,i),checkValue:s,ret:o}},decryptionKey:function(t,r){return{keyPlaintext:a.SM4CryptECB(t,0,r),checkData:g(t).slice(0,8)}},decentralizedMainKey:function(t){var r;r=t,t=Array.prototype.map.call(new Uint8Array(r),(t=>("00"+t.toString(16)).slice(-2))).join(""),console.log("mk="+t);let e="11111111111111111111111111111111",i="22222222222222222222222222222222",n="33333333333333333333333333333333",o=p(e,i,n),s=function(t,r){var e=a.SM4CryptECB("00000000000000000000000000000000",1,t);const i=e.slice(0,8);return{keyCiphertext:a.SM4CryptECB(t,1,r),checkValue:i,ret:e}}(t,o.keyPlaintext);return{p1:e,p2:i,p3:n,p:o,m:s}},base64PkToHexPk:d,getHash:y,getHashAsBase64:function(t,r){var e=y(t,d(r));return{z:e.z,hashHex:e.hex,hashBase64:u.fromByteArray(i.hexToArray(e.hex))}}}},742:(t,r)=>{"use strict";r.byteLength=function(t){var r=u(t),e=r[0],i=r[1];return 3*(e+i)/4-i},r.toByteArray=function(t){var r,e,o=u(t),s=o[0],h=o[1],a=new n(function(t,r,e){return 3*(r+e)/4-e}(0,s,h)),f=0,c=h>0?s-4:s;for(e=0;e<c;e+=4)r=i[t.charCodeAt(e)]<<18|i[t.charCodeAt(e+1)]<<12|i[t.charCodeAt(e+2)]<<6|i[t.charCodeAt(e+3)],a[f++]=r>>16&255,a[f++]=r>>8&255,a[f++]=255&r;return 2===h&&(r=i[t.charCodeAt(e)]<<2|i[t.charCodeAt(e+1)]>>4,a[f++]=255&r),1===h&&(r=i[t.charCodeAt(e)]<<10|i[t.charCodeAt(e+1)]<<4|i[t.charCodeAt(e+2)]>>2,a[f++]=r>>8&255,a[f++]=255&r),a},r.fromByteArray=function(t){for(var r,i=t.length,n=i%3,o=[],s=16383,h=0,u=i-n;h<u;h+=s)o.push(a(t,h,h+s>u?u:h+s));return 1===n?(r=t[i-1],o.push(e[r>>2]+e[r<<4&63]+"==")):2===n&&(r=(t[i-2]<<8)+t[i-1],o.push(e[r>>10]+e[r>>4&63]+e[r<<2&63]+"=")),o.join("")};for(var e=[],i=[],n="undefined"!=typeof Uint8Array?Uint8Array:Array,o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",s=0,h=o.le
2023-08-09 05:57:49 +00:00
//# sourceMappingURL=gmhelper.js.map