- SignalDesk1小时前
Original Summary
跟佬友们一样申请了中银的哔哩哔哩万事达卡,看到有人分享如何查询,就让dsh搓了个查询的油猴脚本。 顺便问下收到卡的佬友,这个状态是不是可以去营业厅催了? 将下面代码在油猴插件新建添加上,刷新一下在油猴脚本运行即可。 // ==UserScript== // @name 中国银行 · 借记卡申请进度查询(卡号 / 状态) // @namespace https://open.boc.cn/bankcard/cardReserve // @version 1.1.0 // @description 任意页面都能用:油猴菜单点一下就查询中行借记卡预约记录,显示制卡卡号与状态。请求走 GM_xmlhttpRequest(不受跨域限制),报文为国密 SM4 + HMAC-SM3 + SM2。 // @author - // @match :/// // @run-at document-idle // @grant GM_xmlhttpRequest // @grant GM_registerMenuCommand // @grant GM_setValue // @grant GM_getValue // @grant unsafeWindow // @connect open.boc.cn // @noframes // ==/UserScript== / eslint-disable no-multi-spaces / (function () { 'use strict'; var U = (typeof unsafeWindow !== 'undefined') ? unsafeWindow : window; var API_HOST = 'https://open.boc.cn'; / ================================================================== 1) 国密算法(SM3 / HMAC-SM3 / SM4-ECB-PKCS7 / SM2-C1C3C2) ================================================================== / / ============================================================ 中国银行 H5 (open.boc.cn) 报文加解密实现 算法:SM4-ECB/PKCS7 + HMAC-SM3 + SM2(C1C3C2) 纯 JS,无任何外部依赖,可同时用于浏览器与 Node ============================================================ / (function (root) { 'use strict'; / ---------------- 工具 ---------------- / var HEX = '0123456789abcdef'; function bytesToHex(b) { var s = '', i; for (i = 0; i < b.length; i++) s += HEX[(b[i] >> 4) & 15] + HEX[b[i] & 15]; return s; } function hexToBytes(h) { h = String(h).replace(/[^0-9a-fA-F]/g, ''); if (h.length % 2) h = '0' + h; var b = new Uint8Array(h.length / 2), i; for (i = 0; i < b.length; i++) b[i] = parseInt(h.substr(i 2, 2), 16); return b; } function utf8ToBytes(s) { if (typeof TextEncoder !== 'undefined') return new TextEncoder().encode(s); var utf8 = unescape(encodeURIComponent(s)), b = new Uint8Array(utf8.length), i; for (i = 0; i < utf8.length; i++) b[i] = utf8.charCodeAt(i) & 0xff; return b; } function bytesToUtf8(b) { if (typeof TextDecoder !== 'undefined') return new TextDecoder().decode(b); var s = '', i; for (i = 0; i < b.length; i++) s += String.fromCharCode(b[i]); return decodeURIComponent(escape(s)); } function concatBytes() { var total = 0, i, j, out, off = 0; for (i = 0; i < arguments.length; i++) total += arguments[i].length; out = new Uint8Array(total); for (i = 0; i < arguments.length; i++) { for (j = 0; j < arguments[i].length; j++) out[off++] = arguments[i][j]; } return out; } function b64encode(bytes) { if (typeof Buffer !== 'undefined') return Buffer.from(bytes).toString('base64'); var s = '', i; for (i = 0; i < bytes.length; i++) s += String.fromCharCode(bytes[i]); return btoa(s); } function b64decode(str) { if (typeof Buffer !== 'undefined') return new Uint8Array(Buffer.from(str, 'base64')); var bin = atob(str), b = new Uint8Array(bin.length), i; for (i = 0; i < bin.length; i++) b[i] = bin.charCodeAt(i); return b; } / ---------------- SM3 ---------------- / var SM3_IV = [0x7380166f, 0x4914b2b9, 0x172442d7, 0xda8a0600, 0xa96f30bc, 0x163138aa, 0xe38dee4d, 0xb0fb0e4e]; function rotl32(x, n) { n &= 31; return ((x << n) | (x >>> (32 - n))) >>> 0; } function p0(x) { return (x ^ rotl32(x, 9) ^ rotl32(x, 17)) >>> 0; } function p1(x) { return (x ^ rotl32(x, 15) ^ rotl32(x, 23)) >>> 0; } function sm3Digest(bytes) { var len = bytes.length; var withPad = new Uint8Array((((len + 8) >> 6) + 1) << 6); withPad.set(bytes, 0); withPad[len] = 0x80; var bitLenHi = Math.floor((len 8) / 4294967296); var bitLenLo = (len 8) >>> 0; var dv = new DataView(withPad.buffer); dv.setUint32(withPad.length - 8, bitLenHi); dv.setUint32(withPad.length - 4, bitLenLo); var V = SM3_IV.slice(0), W = new Array(68), W1 = new Array(64); var i, j, t, ss1, ss2, tt1, tt2, a, b, c, d, e, f, g, h; for (i = 0; i < withPad.length; i += 64) { for (j = 0; j < 16; j++) { W[j] = ((withPad[i + j 4] << 24) | (withPad[i + j 4 + 1] << 16) | (withPad[i + j 4 + 2] << 8) | withPad[i + j 4 + 3]) >>> 0; } for (j = 16; j < 68; j++) { W[j] = (p1((W[j - 16] ^ W[j - 9] ^ rotl32(W[j - 3], 15)) >>> 0) ^ rotl32(W[j - 13], 7) ^ W[j - 6]) >>> 0; } for (j = 0; j < 64; j++) W1[j] = (W[j] ^ W[j + 4]) >>> 0; a = V[0]; b = V[1]; c = V[2]; d = V[3]; e = V[4]; f = V[5]; g = V[6]; h = V[7]; for (j = 0; j < 64; j++) { t = j < 16 ? 0x79cc4519 : 0x7a879d8a; ss1 = rotl32((rotl32(a, 12) + e + rotl32(t, j)) >>> 0, 7); ss2 = (ss1 ^ rotl32(a, 12)) >>> 0; if (j < 16) { tt1 = ((a ^ b ^ c) + d + ss2 + W1[j]) >>> 0; tt2 = ((e ^ f ^ g) + h + ss1 + W[j]) >>> 0; } else { tt1 = (((a & b) | (a & c) | (b & c)) + d + ss2 + W1[j]) >>> 0; tt2 = (((e & f) | (~e & g)) + h + ss1 + W[j]) >>> 0; } d = c; c = rotl32(b, 9); b = a; a = tt1 >>> 0; h = g; g = rotl32(f, 19); f = e; e = p0(tt2); } V[0] = (V[0] ^ a) >>> 0; V[1] = (V[1] ^ b) >>> 0; V[2] = (V[2] ^ c) >>> 0; V[3] = (V[3] ^ d) >>> 0; V[4] = (V[4] ^ e) >>> 0; V[5] = (V[5] ^ f) >>> 0; V[6] = (V[6] ^ g) >>> 0; V[7] = (V[7] ^ h) >>> 0; } var out = new Uint8Array(32); var odv = new DataView(out.buffer); for (i = 0; i < 8; i++) odv.setUint32(i 4, V[i]); return out; } function sm3Hex(bytes) { return bytesToHex(sm3Digest(bytes)); } / HMAC-SM3:key 为 16 字节(由 16 位字符串转 hex 再还原),分组 64 字节 / function hmacSm3Hex(keyBytes, msgBytes) { var blockLen = 64, i; var key = keyBytes; if (key.length > blockLen) key = sm3Digest(key); var pad = new Uint8Array(blockLen); pad.set(key, 0); var ipad = new Uint8Array(blockLen), opad = new Uint8Array(blockLen); for (i = 0; i < blockLen; i++) { ipad[i] = pad[i] ^ 0x36; opad[i] = pad[i] ^ 0x5c; } return bytesToHex(sm3Digest(concatBytes(opad, sm3Digest(concatBytes(ipad, msgBytes))))); } / ---------------- SM4 (ECB / PKCS7) ---------------- */ var SM4_SBO
- 情报分类:硬件与数码
- 分类依据:内容涉及硬件、数码产品或通信卡
- 信息来源:服务器 / LINUX DO - 最新话题
- 发布时间:2026/10/12 15:08:44
- 暂无回复