This commit is contained in:
cheney
2023-08-09 13:58:15 +08:00
parent dd6405ff4d
commit f42de135d5
2250 changed files with 0 additions and 314928 deletions
-1
View File
@@ -1 +0,0 @@
/node_modules/
-226
View File
@@ -1,226 +0,0 @@
function check(v, re, msg) {
if (!re.test(v)) {
alert(msg)
}
}
function padPkcs7(data) {
var d = data.length % 16;
d = 16 - d;
var arr = Array.from(data)
for (var i = 0; i < d; i++) {
arr.push(d)
}
return arr;
}
function stripPcks7(data) {
var arr = Array.from(data)
var padder = arr[arr.length - 1];
return arr.slice(0, arr.length - padder);
}
function ecb(bytes, cb) {
var ret = []
for (var i = 0; i < bytes.length; i += 16) {
var d = bytes.slice(i, i + 16);
var en = cb(d)
ret = ret.concat(Array.from(en))
}
return ret;
}
function stringToHex(str){
var val = "";
for (var i = 0; i < str.length; i++) {
var v = str.charCodeAt(i).toString(16);
if ( v.length < 2 ) {
v = "0" + v;
}
val += v;
}
return val
}
function hexToString(hex){
var arr = hex.split("")
var out = ""
for (var i = 0; i < arr.length / 2; i++) {
var tmp = "0x" + arr[i * 2] + arr[i * 2 + 1]
var charValue = String.fromCharCode(tmp);
out += charValue
}
return out
}
class ActiveIC {
constructor() {
this.server = "ws://127.0.0.1:12322/active";
this.waitMap = {}
}
__debug(...str) {
if (window.active_debug) {
console.log(...str)
}
}
connect() {
this.__debug("connect")
var _this = this;
try {
if (this.sock) {
this.sock.onclose = function () {
}
this.sock.close()
}
this.sock = new WebSocket(this.server);
this.__debug("sock")
this.sock.onopen = function () {
_this.__debug("open");
_this.sock.isopened = true;
_this.sock.onmessage = function (e) {
_this.__debug(e.data)
var ret = JSON.parse(e.data);
var cb = _this.waitMap[ret.id]
cb && cb(ret)
}
};
this.sock.onclose = function () {
_this.sock.isopened = false;
_this.__debug("close");
_this.reconnect();
};
// this.sock.onerror = function () {
// _this.sock.isopened = false;
// this.__debug("onerror");
// _this.reconnect();
// };
} catch (e) {
_this.__debug("onerror");
_this.reconnect();
}
}
reconnect() {
this.__debug("reconnect")
var _this = this;
if (_this.sock && _this.sock.isopened) {
this.__debug("miss")
return
}
setTimeout(function () {
_this.connect();
}, 3000);
}
__send(cmd, param, cb) {
var id = (Math.random() + "").substr(2);
this.sock.send(
JSON.stringify({
id: id,
cmd: cmd,
param: param
})
);
if (cb) {
this.waitMap[id] = cb;
}
}
__check(v, re, msg, reject) {
if (!re.test(v)) {
reject && reject({
msg,
code: "C0"
})
}
}
readText(addr, len) {
var _this = this;
return new Promise(function (resolve, reject) {
if (!_this.sock || !_this.sock.isopened) {
reject({
code: "CB",
msg: "Active 通信失败"
})
}
_this.__check(addr, /\d{1,2}/g, "用户编号填写错误!", reject);
_this.__check(len, /\d{1,2}/g, "用户类型填写错误!", reject);
_this.__send("read", {
addr, len
}, function (ret) {
if (ret.code === "00") {
resolve(ret)
} else {
reject(ret)
}
})
})
}
writeText(addr, data) {
return this.writeHex(addr, stringToHex( data ))
}
writeHex(addr, data) {
var _this = this;
return new Promise(function (resolve, reject) {
if (!_this.sock || !_this.sock.isopened) {
reject({
code: "CB",
msg: "Active 通信失败"
})
}
_this.__check(addr, /\d{1,2}/g, "地址填写错误!", reject);
_this.__check(data, /^([A-Fa-f0-9][A-Fa-f0-9])+$/g, "数据填写错误!", reject);
_this.__send("write", {
addr, data
}, function (ret) {
if (ret.code === "00") {
resolve(ret)
} else {
reject(ret)
}
})
})
}
}
/**
* 检测通过返回 true
* 检测不通过返回 fase
*/
ActiveIC.checkSupport = function () {
try {
if (!!window.WebSocket && window.WebSocket.prototype.send) {
return true;
} else {
console.error("您的浏览器不支持!")
return false;
}
} catch (e) {
console.error("当前环境不支持!", e)
return false;
}
}
Binary file not shown.
-851
View File
@@ -1,851 +0,0 @@
/**
* DES加密/解密
* @Copyright Copyright (c) 2006
* @author Guapo
* @see DESCore
*/
/*
* encrypt the string to string made up of hex
* return the encrypted string
*/
var defaultKey="app@@server";
function desEnc(data){
return strEnc(data,defaultKey);
}
function desDec(data){
return strDec(data,defaultKey);
}
function strEnc(data,firstKey,secondKey,thirdKey){
var leng = data.length;
var encData = "";
var firstKeyBt,secondKeyBt,thirdKeyBt,firstLength,secondLength,thirdLength;
if(firstKey != null && firstKey != ""){
firstKeyBt = getKeyBytes(firstKey);
firstLength = firstKeyBt.length;
}
if(secondKey != null && secondKey != ""){
secondKeyBt = getKeyBytes(secondKey);
secondLength = secondKeyBt.length;
}
if(thirdKey != null && thirdKey != ""){
thirdKeyBt = getKeyBytes(thirdKey);
thirdLength = thirdKeyBt.length;
}
if(leng > 0){
if(leng < 4){
var bt = strToBt(data);
var encByte ;
if(firstKey != null && firstKey !="" && secondKey != null && secondKey != "" && thirdKey != null && thirdKey != ""){
var tempBt;
var x,y,z;
tempBt = bt;
for(x = 0;x < firstLength ;x ++){
tempBt = enc(tempBt,firstKeyBt[x]);
}
for(y = 0;y < secondLength ;y ++){
tempBt = enc(tempBt,secondKeyBt[y]);
}
for(z = 0;z < thirdLength ;z ++){
tempBt = enc(tempBt,thirdKeyBt[z]);
}
encByte = tempBt;
}else{
if(firstKey != null && firstKey !="" && secondKey != null && secondKey != ""){
var tempBt;
var x,y;
tempBt = bt;
for(x = 0;x < firstLength ;x ++){
tempBt = enc(tempBt,firstKeyBt[x]);
}
for(y = 0;y < secondLength ;y ++){
tempBt = enc(tempBt,secondKeyBt[y]);
}
encByte = tempBt;
}else{
if(firstKey != null && firstKey !=""){
var tempBt;
var x = 0;
tempBt = bt;
for(x = 0;x < firstLength ;x ++){
tempBt = enc(tempBt,firstKeyBt[x]);
}
encByte = tempBt;
}
}
}
encData = bt64ToHex(encByte);
}else{
var iterator = parseInt(leng/4);
var remainder = leng%4;
var i=0;
for(i = 0;i < iterator;i++){
var tempData = data.substring(i*4+0,i*4+4);
var tempByte = strToBt(tempData);
var encByte ;
if(firstKey != null && firstKey !="" && secondKey != null && secondKey != "" && thirdKey != null && thirdKey != ""){
var tempBt;
var x,y,z;
tempBt = tempByte;
for(x = 0;x < firstLength ;x ++){
tempBt = enc(tempBt,firstKeyBt[x]);
}
for(y = 0;y < secondLength ;y ++){
tempBt = enc(tempBt,secondKeyBt[y]);
}
for(z = 0;z < thirdLength ;z ++){
tempBt = enc(tempBt,thirdKeyBt[z]);
}
encByte = tempBt;
}else{
if(firstKey != null && firstKey !="" && secondKey != null && secondKey != ""){
var tempBt;
var x,y;
tempBt = tempByte;
for(x = 0;x < firstLength ;x ++){
tempBt = enc(tempBt,firstKeyBt[x]);
}
for(y = 0;y < secondLength ;y ++){
tempBt = enc(tempBt,secondKeyBt[y]);
}
encByte = tempBt;
}else{
if(firstKey != null && firstKey !=""){
var tempBt;
var x;
tempBt = tempByte;
for(x = 0;x < firstLength ;x ++){
tempBt = enc(tempBt,firstKeyBt[x]);
}
encByte = tempBt;
}
}
}
encData += bt64ToHex(encByte);
}
if(remainder > 0){
var remainderData = data.substring(iterator*4+0,leng);
var tempByte = strToBt(remainderData);
var encByte ;
if(firstKey != null && firstKey !="" && secondKey != null && secondKey != "" && thirdKey != null && thirdKey != ""){
var tempBt;
var x,y,z;
tempBt = tempByte;
for(x = 0;x < firstLength ;x ++){
tempBt = enc(tempBt,firstKeyBt[x]);
}
for(y = 0;y < secondLength ;y ++){
tempBt = enc(tempBt,secondKeyBt[y]);
}
for(z = 0;z < thirdLength ;z ++){
tempBt = enc(tempBt,thirdKeyBt[z]);
}
encByte = tempBt;
}else{
if(firstKey != null && firstKey !="" && secondKey != null && secondKey != ""){
var tempBt;
var x,y;
tempBt = tempByte;
for(x = 0;x < firstLength ;x ++){
tempBt = enc(tempBt,firstKeyBt[x]);
}
for(y = 0;y < secondLength ;y ++){
tempBt = enc(tempBt,secondKeyBt[y]);
}
encByte = tempBt;
}else{
if(firstKey != null && firstKey !=""){
var tempBt;
var x;
tempBt = tempByte;
for(x = 0;x < firstLength ;x ++){
tempBt = enc(tempBt,firstKeyBt[x]);
}
encByte = tempBt;
}
}
}
encData += bt64ToHex(encByte);
}
}
}
return encData;
}
/*
* decrypt the encrypted string to the original string
*
* return the original string
*/
function strDec(data,firstKey,secondKey,thirdKey){
var leng = data.length;
var decStr = "";
var firstKeyBt,secondKeyBt,thirdKeyBt,firstLength,secondLength,thirdLength;
if(firstKey != null && firstKey != ""){
firstKeyBt = getKeyBytes(firstKey);
firstLength = firstKeyBt.length;
}
if(secondKey != null && secondKey != ""){
secondKeyBt = getKeyBytes(secondKey);
secondLength = secondKeyBt.length;
}
if(thirdKey != null && thirdKey != ""){
thirdKeyBt = getKeyBytes(thirdKey);
thirdLength = thirdKeyBt.length;
}
var iterator = parseInt(leng/16);
var i=0;
for(i = 0;i < iterator;i++){
var tempData = data.substring(i*16+0,i*16+16);
var strByte = hexToBt64(tempData);
var intByte = new Array(64);
var j = 0;
for(j = 0;j < 64; j++){
intByte[j] = parseInt(strByte.substring(j,j+1));
}
var decByte;
if(firstKey != null && firstKey !="" && secondKey != null && secondKey != "" && thirdKey != null && thirdKey != ""){
var tempBt;
var x,y,z;
tempBt = intByte;
for(x = thirdLength - 1;x >= 0;x --){
tempBt = dec(tempBt,thirdKeyBt[x]);
}
for(y = secondLength - 1;y >= 0;y --){
tempBt = dec(tempBt,secondKeyBt[y]);
}
for(z = firstLength - 1;z >= 0 ;z --){
tempBt = dec(tempBt,firstKeyBt[z]);
}
decByte = tempBt;
}else{
if(firstKey != null && firstKey !="" && secondKey != null && secondKey != ""){
var tempBt;
var x,y,z;
tempBt = intByte;
for(x = secondLength - 1;x >= 0 ;x --){
tempBt = dec(tempBt,secondKeyBt[x]);
}
for(y = firstLength - 1;y >= 0 ;y --){
tempBt = dec(tempBt,firstKeyBt[y]);
}
decByte = tempBt;
}else{
if(firstKey != null && firstKey !=""){
var tempBt;
var x,y,z;
tempBt = intByte;
for(x = firstLength - 1;x >= 0 ;x --){
tempBt = dec(tempBt,firstKeyBt[x]);
}
decByte = tempBt;
}
}
}
decStr += byteToString(decByte);
}
return decStr;
}
/*
* chang the string into the bit array
*
* return bit array(it's length % 64 = 0)
*/
function getKeyBytes(key){
var keyBytes = new Array();
var leng = key.length;
var iterator = parseInt(leng/4);
var remainder = leng%4;
var i = 0;
for(i = 0;i < iterator; i ++){
keyBytes[i] = strToBt(key.substring(i*4+0,i*4+4));
}
if(remainder > 0){
keyBytes[i] = strToBt(key.substring(i*4+0,leng));
}
return keyBytes;
}
/*
* chang the string(it's length <= 4) into the bit array
*
* return bit array(it's length = 64)
*/
function strToBt(str){
var leng = str.length;
var bt = new Array(64);
if(leng < 4){
var i=0,j=0,p=0,q=0;
for(i = 0;i<leng;i++){
var k = str.charCodeAt(i);
for(j=0;j<16;j++){
var pow=1,m=0;
for(m=15;m>j;m--){
pow *= 2;
}
bt[16*i+j]=parseInt(k/pow)%2;
}
}
for(p = leng;p<4;p++){
var k = 0;
for(q=0;q<16;q++){
var pow=1,m=0;
for(m=15;m>q;m--){
pow *= 2;
}
bt[16*p+q]=parseInt(k/pow)%2;
}
}
}else{
for(i = 0;i<4;i++){
var k = str.charCodeAt(i);
for(j=0;j<16;j++){
var pow=1;
for(m=15;m>j;m--){
pow *= 2;
}
bt[16*i+j]=parseInt(k/pow)%2;
}
}
}
return bt;
}
/*
* chang the bit(it's length = 4) into the hex
*
* return hex
*/
function bt4ToHex(binary) {
var hex;
switch (binary) {
case "0000" : hex = "0"; break;
case "0001" : hex = "1"; break;
case "0010" : hex = "2"; break;
case "0011" : hex = "3"; break;
case "0100" : hex = "4"; break;
case "0101" : hex = "5"; break;
case "0110" : hex = "6"; break;
case "0111" : hex = "7"; break;
case "1000" : hex = "8"; break;
case "1001" : hex = "9"; break;
case "1010" : hex = "A"; break;
case "1011" : hex = "B"; break;
case "1100" : hex = "C"; break;
case "1101" : hex = "D"; break;
case "1110" : hex = "E"; break;
case "1111" : hex = "F"; break;
}
return hex;
}
/*
* chang the hex into the bit(it's length = 4)
*
* return the bit(it's length = 4)
*/
function hexToBt4(hex) {
var binary;
switch (hex) {
case "0" : binary = "0000"; break;
case "1" : binary = "0001"; break;
case "2" : binary = "0010"; break;
case "3" : binary = "0011"; break;
case "4" : binary = "0100"; break;
case "5" : binary = "0101"; break;
case "6" : binary = "0110"; break;
case "7" : binary = "0111"; break;
case "8" : binary = "1000"; break;
case "9" : binary = "1001"; break;
case "A" : binary = "1010"; break;
case "B" : binary = "1011"; break;
case "C" : binary = "1100"; break;
case "D" : binary = "1101"; break;
case "E" : binary = "1110"; break;
case "F" : binary = "1111"; break;
}
return binary;
}
/*
* chang the bit(it's length = 64) into the string
*
* return string
*/
function byteToString(byteData){
var str="";
for(i = 0;i<4;i++){
var count=0;
for(j=0;j<16;j++){
var pow=1;
for(m=15;m>j;m--){
pow*=2;
}
count+=byteData[16*i+j]*pow;
}
if(count != 0){
str+=String.fromCharCode(count);
}
}
return str;
}
function bt64ToHex(byteData){
var hex = "";
for(i = 0;i<16;i++){
var bt = "";
for(j=0;j<4;j++){
bt += byteData[i*4+j];
}
hex+=bt4ToHex(bt);
}
return hex;
}
function hexToBt64(hex){
var binary = "";
for(i = 0;i<16;i++){
binary+=hexToBt4(hex.substring(i,i+1));
}
return binary;
}
/*
* the 64 bit des core arithmetic
*/
function enc(dataByte,keyByte){
var keys = generateKeys(keyByte);
var ipByte = initPermute(dataByte);
var ipLeft = new Array(32);
var ipRight = new Array(32);
var tempLeft = new Array(32);
var i = 0,j = 0,k = 0,m = 0, n = 0;
for(k = 0;k < 32;k ++){
ipLeft[k] = ipByte[k];
ipRight[k] = ipByte[32+k];
}
for(i = 0;i < 16;i ++){
for(j = 0;j < 32;j ++){
tempLeft[j] = ipLeft[j];
ipLeft[j] = ipRight[j];
}
var key = new Array(48);
for(m = 0;m < 48;m ++){
key[m] = keys[i][m];
}
var tempRight = xor(pPermute(sBoxPermute(xor(expandPermute(ipRight),key))), tempLeft);
for(n = 0;n < 32;n ++){
ipRight[n] = tempRight[n];
}
}
var finalData =new Array(64);
for(i = 0;i < 32;i ++){
finalData[i] = ipRight[i];
finalData[32+i] = ipLeft[i];
}
return finallyPermute(finalData);
}
function dec(dataByte,keyByte){
var keys = generateKeys(keyByte);
var ipByte = initPermute(dataByte);
var ipLeft = new Array(32);
var ipRight = new Array(32);
var tempLeft = new Array(32);
var i = 0,j = 0,k = 0,m = 0, n = 0;
for(k = 0;k < 32;k ++){
ipLeft[k] = ipByte[k];
ipRight[k] = ipByte[32+k];
}
for(i = 15;i >= 0;i --){
for(j = 0;j < 32;j ++){
tempLeft[j] = ipLeft[j];
ipLeft[j] = ipRight[j];
}
var key = new Array(48);
for(m = 0;m < 48;m ++){
key[m] = keys[i][m];
}
var tempRight = xor(pPermute(sBoxPermute(xor(expandPermute(ipRight),key))), tempLeft);
for(n = 0;n < 32;n ++){
ipRight[n] = tempRight[n];
}
}
var finalData =new Array(64);
for(i = 0;i < 32;i ++){
finalData[i] = ipRight[i];
finalData[32+i] = ipLeft[i];
}
return finallyPermute(finalData);
}
function initPermute(originalData){
var ipByte = new Array(64);
for (i = 0, m = 1, n = 0; i < 4; i++, m += 2, n += 2) {
for (j = 7, k = 0; j >= 0; j--, k++) {
ipByte[i * 8 + k] = originalData[j * 8 + m];
ipByte[i * 8 + k + 32] = originalData[j * 8 + n];
}
}
return ipByte;
}
function expandPermute(rightData){
var epByte = new Array(48);
for (i = 0; i < 8; i++) {
if (i == 0) {
epByte[i * 6 + 0] = rightData[31];
} else {
epByte[i * 6 + 0] = rightData[i * 4 - 1];
}
epByte[i * 6 + 1] = rightData[i * 4 + 0];
epByte[i * 6 + 2] = rightData[i * 4 + 1];
epByte[i * 6 + 3] = rightData[i * 4 + 2];
epByte[i * 6 + 4] = rightData[i * 4 + 3];
if (i == 7) {
epByte[i * 6 + 5] = rightData[0];
} else {
epByte[i * 6 + 5] = rightData[i * 4 + 4];
}
}
return epByte;
}
function xor(byteOne,byteTwo){
var xorByte = new Array(byteOne.length);
for(i = 0;i < byteOne.length; i ++){
xorByte[i] = byteOne[i] ^ byteTwo[i];
}
return xorByte;
}
function sBoxPermute(expandByte){
var sBoxByte = new Array(32);
var binary = "";
var s1 = [
[14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7],
[0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8],
[4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0],
[15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13 ]];
/* Table - s2 */
var s2 = [
[15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10],
[3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5],
[0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15],
[13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9 ]];
/* Table - s3 */
var s3= [
[10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8],
[13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1],
[13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7],
[1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12 ]];
/* Table - s4 */
var s4 = [
[7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15],
[13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9],
[10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4],
[3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14 ]];
/* Table - s5 */
var s5 = [
[2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9],
[14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6],
[4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14],
[11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3 ]];
/* Table - s6 */
var s6 = [
[12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11],
[10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8],
[9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6],
[4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13 ]];
/* Table - s7 */
var s7 = [
[4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1],
[13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6],
[1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2],
[6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12]];
/* Table - s8 */
var s8 = [
[13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7],
[1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2],
[7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8],
[2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11]];
for(m=0;m<8;m++){
var i=0,j=0;
i = expandByte[m*6+0]*2+expandByte[m*6+5];
j = expandByte[m * 6 + 1] * 2 * 2 * 2
+ expandByte[m * 6 + 2] * 2* 2
+ expandByte[m * 6 + 3] * 2
+ expandByte[m * 6 + 4];
switch (m) {
case 0 :
binary = getBoxBinary(s1[i][j]);
break;
case 1 :
binary = getBoxBinary(s2[i][j]);
break;
case 2 :
binary = getBoxBinary(s3[i][j]);
break;
case 3 :
binary = getBoxBinary(s4[i][j]);
break;
case 4 :
binary = getBoxBinary(s5[i][j]);
break;
case 5 :
binary = getBoxBinary(s6[i][j]);
break;
case 6 :
binary = getBoxBinary(s7[i][j]);
break;
case 7 :
binary = getBoxBinary(s8[i][j]);
break;
}
sBoxByte[m*4+0] = parseInt(binary.substring(0,1));
sBoxByte[m*4+1] = parseInt(binary.substring(1,2));
sBoxByte[m*4+2] = parseInt(binary.substring(2,3));
sBoxByte[m*4+3] = parseInt(binary.substring(3,4));
}
return sBoxByte;
}
function pPermute(sBoxByte){
var pBoxPermute = new Array(32);
pBoxPermute[ 0] = sBoxByte[15];
pBoxPermute[ 1] = sBoxByte[ 6];
pBoxPermute[ 2] = sBoxByte[19];
pBoxPermute[ 3] = sBoxByte[20];
pBoxPermute[ 4] = sBoxByte[28];
pBoxPermute[ 5] = sBoxByte[11];
pBoxPermute[ 6] = sBoxByte[27];
pBoxPermute[ 7] = sBoxByte[16];
pBoxPermute[ 8] = sBoxByte[ 0];
pBoxPermute[ 9] = sBoxByte[14];
pBoxPermute[10] = sBoxByte[22];
pBoxPermute[11] = sBoxByte[25];
pBoxPermute[12] = sBoxByte[ 4];
pBoxPermute[13] = sBoxByte[17];
pBoxPermute[14] = sBoxByte[30];
pBoxPermute[15] = sBoxByte[ 9];
pBoxPermute[16] = sBoxByte[ 1];
pBoxPermute[17] = sBoxByte[ 7];
pBoxPermute[18] = sBoxByte[23];
pBoxPermute[19] = sBoxByte[13];
pBoxPermute[20] = sBoxByte[31];
pBoxPermute[21] = sBoxByte[26];
pBoxPermute[22] = sBoxByte[ 2];
pBoxPermute[23] = sBoxByte[ 8];
pBoxPermute[24] = sBoxByte[18];
pBoxPermute[25] = sBoxByte[12];
pBoxPermute[26] = sBoxByte[29];
pBoxPermute[27] = sBoxByte[ 5];
pBoxPermute[28] = sBoxByte[21];
pBoxPermute[29] = sBoxByte[10];
pBoxPermute[30] = sBoxByte[ 3];
pBoxPermute[31] = sBoxByte[24];
return pBoxPermute;
}
function finallyPermute(endByte){
var fpByte = new Array(64);
fpByte[ 0] = endByte[39];
fpByte[ 1] = endByte[ 7];
fpByte[ 2] = endByte[47];
fpByte[ 3] = endByte[15];
fpByte[ 4] = endByte[55];
fpByte[ 5] = endByte[23];
fpByte[ 6] = endByte[63];
fpByte[ 7] = endByte[31];
fpByte[ 8] = endByte[38];
fpByte[ 9] = endByte[ 6];
fpByte[10] = endByte[46];
fpByte[11] = endByte[14];
fpByte[12] = endByte[54];
fpByte[13] = endByte[22];
fpByte[14] = endByte[62];
fpByte[15] = endByte[30];
fpByte[16] = endByte[37];
fpByte[17] = endByte[ 5];
fpByte[18] = endByte[45];
fpByte[19] = endByte[13];
fpByte[20] = endByte[53];
fpByte[21] = endByte[21];
fpByte[22] = endByte[61];
fpByte[23] = endByte[29];
fpByte[24] = endByte[36];
fpByte[25] = endByte[ 4];
fpByte[26] = endByte[44];
fpByte[27] = endByte[12];
fpByte[28] = endByte[52];
fpByte[29] = endByte[20];
fpByte[30] = endByte[60];
fpByte[31] = endByte[28];
fpByte[32] = endByte[35];
fpByte[33] = endByte[ 3];
fpByte[34] = endByte[43];
fpByte[35] = endByte[11];
fpByte[36] = endByte[51];
fpByte[37] = endByte[19];
fpByte[38] = endByte[59];
fpByte[39] = endByte[27];
fpByte[40] = endByte[34];
fpByte[41] = endByte[ 2];
fpByte[42] = endByte[42];
fpByte[43] = endByte[10];
fpByte[44] = endByte[50];
fpByte[45] = endByte[18];
fpByte[46] = endByte[58];
fpByte[47] = endByte[26];
fpByte[48] = endByte[33];
fpByte[49] = endByte[ 1];
fpByte[50] = endByte[41];
fpByte[51] = endByte[ 9];
fpByte[52] = endByte[49];
fpByte[53] = endByte[17];
fpByte[54] = endByte[57];
fpByte[55] = endByte[25];
fpByte[56] = endByte[32];
fpByte[57] = endByte[ 0];
fpByte[58] = endByte[40];
fpByte[59] = endByte[ 8];
fpByte[60] = endByte[48];
fpByte[61] = endByte[16];
fpByte[62] = endByte[56];
fpByte[63] = endByte[24];
return fpByte;
}
function getBoxBinary(i) {
var binary = "";
switch (i) {
case 0 :binary = "0000";break;
case 1 :binary = "0001";break;
case 2 :binary = "0010";break;
case 3 :binary = "0011";break;
case 4 :binary = "0100";break;
case 5 :binary = "0101";break;
case 6 :binary = "0110";break;
case 7 :binary = "0111";break;
case 8 :binary = "1000";break;
case 9 :binary = "1001";break;
case 10 :binary = "1010";break;
case 11 :binary = "1011";break;
case 12 :binary = "1100";break;
case 13 :binary = "1101";break;
case 14 :binary = "1110";break;
case 15 :binary = "1111";break;
}
return binary;
}
/*
* generate 16 keys for xor
*
*/
function generateKeys(keyByte){
var key = new Array(56);
var keys = new Array();
keys[ 0] = new Array();
keys[ 1] = new Array();
keys[ 2] = new Array();
keys[ 3] = new Array();
keys[ 4] = new Array();
keys[ 5] = new Array();
keys[ 6] = new Array();
keys[ 7] = new Array();
keys[ 8] = new Array();
keys[ 9] = new Array();
keys[10] = new Array();
keys[11] = new Array();
keys[12] = new Array();
keys[13] = new Array();
keys[14] = new Array();
keys[15] = new Array();
var loop = [1,1,2,2,2,2,2,2,1,2,2,2,2,2,2,1];
for(i=0;i<7;i++){
for(j=0,k=7;j<8;j++,k--){
key[i*8+j]=keyByte[8*k+i];
}
}
var i = 0;
for(i = 0;i < 16;i ++){
var tempLeft=0;
var tempRight=0;
for(j = 0; j < loop[i];j ++){
tempLeft = key[0];
tempRight = key[28];
for(k = 0;k < 27 ;k ++){
key[k] = key[k+1];
key[28+k] = key[29+k];
}
key[27]=tempLeft;
key[55]=tempRight;
}
var tempKey = new Array(48);
tempKey[ 0] = key[13];
tempKey[ 1] = key[16];
tempKey[ 2] = key[10];
tempKey[ 3] = key[23];
tempKey[ 4] = key[ 0];
tempKey[ 5] = key[ 4];
tempKey[ 6] = key[ 2];
tempKey[ 7] = key[27];
tempKey[ 8] = key[14];
tempKey[ 9] = key[ 5];
tempKey[10] = key[20];
tempKey[11] = key[ 9];
tempKey[12] = key[22];
tempKey[13] = key[18];
tempKey[14] = key[11];
tempKey[15] = key[ 3];
tempKey[16] = key[25];
tempKey[17] = key[ 7];
tempKey[18] = key[15];
tempKey[19] = key[ 6];
tempKey[20] = key[26];
tempKey[21] = key[19];
tempKey[22] = key[12];
tempKey[23] = key[ 1];
tempKey[24] = key[40];
tempKey[25] = key[51];
tempKey[26] = key[30];
tempKey[27] = key[36];
tempKey[28] = key[46];
tempKey[29] = key[54];
tempKey[30] = key[29];
tempKey[31] = key[39];
tempKey[32] = key[50];
tempKey[33] = key[44];
tempKey[34] = key[32];
tempKey[35] = key[47];
tempKey[36] = key[43];
tempKey[37] = key[48];
tempKey[38] = key[38];
tempKey[39] = key[55];
tempKey[40] = key[33];
tempKey[41] = key[52];
tempKey[42] = key[45];
tempKey[43] = key[41];
tempKey[44] = key[49];
tempKey[45] = key[35];
tempKey[46] = key[28];
tempKey[47] = key[31];
switch(i){
case 0: for(m=0;m < 48 ;m++){ keys[ 0][m] = tempKey[m]; } break;
case 1: for(m=0;m < 48 ;m++){ keys[ 1][m] = tempKey[m]; } break;
case 2: for(m=0;m < 48 ;m++){ keys[ 2][m] = tempKey[m]; } break;
case 3: for(m=0;m < 48 ;m++){ keys[ 3][m] = tempKey[m]; } break;
case 4: for(m=0;m < 48 ;m++){ keys[ 4][m] = tempKey[m]; } break;
case 5: for(m=0;m < 48 ;m++){ keys[ 5][m] = tempKey[m]; } break;
case 6: for(m=0;m < 48 ;m++){ keys[ 6][m] = tempKey[m]; } break;
case 7: for(m=0;m < 48 ;m++){ keys[ 7][m] = tempKey[m]; } break;
case 8: for(m=0;m < 48 ;m++){ keys[ 8][m] = tempKey[m]; } break;
case 9: for(m=0;m < 48 ;m++){ keys[ 9][m] = tempKey[m]; } break;
case 10: for(m=0;m < 48 ;m++){ keys[10][m] = tempKey[m]; } break;
case 11: for(m=0;m < 48 ;m++){ keys[11][m] = tempKey[m]; } break;
case 12: for(m=0;m < 48 ;m++){ keys[12][m] = tempKey[m]; } break;
case 13: for(m=0;m < 48 ;m++){ keys[13][m] = tempKey[m]; } break;
case 14: for(m=0;m < 48 ;m++){ keys[14][m] = tempKey[m]; } break;
case 15: for(m=0;m < 48 ;m++){ keys[15][m] = tempKey[m]; } break;
}
}
return keys;
}
//end-------------------------------------------------------------------------------------------------------------
-404
View File
@@ -1,404 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>IC 卡维护工具</title>
<style>
:root {
--mainColor: #0062cc;
}
html, body {
margin: 0;
width: 100%;
height: 100%;
}
.title {
color: var(--mainColor);
}
.container {
margin: 2rem auto;
border: var(--mainColor) solid 2px;
border-radius: 10px;
width: 80%;
height: 80%;
text-align: left;
}
.group {
padding: 1rem;
margin: 1rem;
}
.form input {
display: block;
margin: 0.5rem 0;
}
.line span {
display: inline-block;
width: 150px;
font-size: 0.8rem;
color: var(--mainColor);
}
</style>
<link rel="stylesheet" type="text/css" href="tabs.css">
<link rel="stylesheet" type="text/css" href="layx.min.css">
</head>
<body>
<div style="width: 100%; text-align: center;">
<h2 class="title">信雅达 IC 卡发行工具</h2>
</div>
<div class="container">
<div class="group" style="height: 10rem">
<ul class="tabs">
<li>
<a href="#" name="tab_public">IC 卡发行</a>
</li>
<li>
<a href="#" name="tab_file">内部信息维护</a>
</li>
<li>
<a href="#" name="tab_active">Active 程序</a>
</li>
</ul>
<div class="tabs-content">
<div class="tab tab_public">
<div style="float: right; width: 500px">
<h4 style="color: var(--mainColor)">帮助</h4>
<ul>
<li>
<span style="color: var(--mainColor); ">清空</span>
<p>仅清空 3 个输入框。</p>
</li>
<li>
<span style="color: var(--mainColor); ">临存</span>
<p>将 3 个输入框的内容临时保存在本地。</p>
</li>
<li>
<span style="color: var(--mainColor); ">临取</span>
<p>将临时保存在本地的信息填入 3 个输入框。</p>
</li>
<li>
<span style="color: var(--mainColor); ">返显</span>
<p>尝试读取 IC 卡内部信息。IC 卡内部信息错误时有可能显示乱码。</p>
</li>
<li>
<span style="color: var(--mainColor); ">发行</span>
<p>将发行信息写入 IC 卡。</p>
</li>
</ul>
</div>
<div class="form" style="padding-top: 2rem">
<input id="manufactor" style="width: 300px; height: 1.06rem" type="text" value="" maxlength="8"
placeholder="厂家标记(长度 8)">
<input id="system" style="width: 300px; height: 1.06rem" type="text" value="" maxlength="8" placeholder="系统信息(长度 8)">
<input id="customer" style="width: 300px; height: 1.06rem" type="text" value="" maxlength="16" placeholder="客户信息(长度 16)">
</div>
<div style="margin: 1rem 0 ">
<button id="btn_nameplate_clear" style="margin-right: 1rem">清空</button>
<button id="btn_nameplate_tmp_save" style="margin-right: 1rem">临存</button>
<button id="btn_nameplate_tmp_load" style="margin-right: 1rem">临取</button>
<button id="btn_nameplate_read" style="margin-right: 1rem">返显</button>
</div>
<button id="btn_nameplate_release" style="margin-right: 1rem">发&emsp;&emsp;行</button>
</div>
<div class="tab tab_file">
<div style="float: right; width: 500px">
<h4 style="color: var(--mainColor)">帮助</h4>
<p>本页所有值都是 HEX</p>
</div>
<div style="height: 1rem"></div>
<div class="line">
<span>IC卡属主 (20h+1)</span>
<input id="path1" style="width: 300px; height: 1.06rem" type="text" value="" maxlength="2"
placeholder="31/32/33">
</div>
<div class="line">
<span>主密钥校验值 (30h+4)</span>
<input id="path2" style="width: 300px; height: 1.06rem" type="text" maxlength="32" value=""
placeholder="主密钥校验值">
</div>
<div class="line">
<span>主密钥密文 (40h+16)</span>
<input id="path3" style="width: 300px; height: 1.06rem" type="text" value=""
placeholder="主密钥密文">
</div>
<div class="line">
<span>保护密钥校验值 (50h+4)</span>
<input id="path4" style="width: 300px; height: 1.06rem" type="text" value=""
placeholder="保护密钥校验值">
</div>
<div class="line">
<span>保护密钥分量(60h+16)</span>
<input id="path5" style="width: 300px; height: 1.06rem" type="text" value=""
placeholder="保护密钥分量">
</div>
<div style="margin-top: 1rem">
<button id="btn_read">读取所有</button>
<button id="btn_write">写入所有</button>
<button id="btn_clear">清空</button>
</div>
</div>
<div class="tab tab_active" style="padding-top: 1rem">
<ul>
<li>
<h4 style="color: var(--mainColor);">V1.0 <a href="./active_ic_setup.exe" style="font-size: 0.5rem; font-weight: normal; cursor: pointer">(点击下载)</a> </h4>
<p>【2022年12月22日】</p>
<p>第一个发行版本</p>
</li>
</ul>
</div>
</div>
</div>
</div>
<!-- UKey 支持, 共 3 个 js-->
<!-- jquery -->
<script type="text/javascript" src="./jquery.min.js"></script>
<script type="text/javascript" src="./active.ic.min.js"></script>
<!-- 演示程序 -->
<script type="text/javascript" src="./tabs.js"></script>
<script type="application/javascript" src="layx.min.js"></script>
<script type="application/javascript" src="tools.js"></script>
<script type="application/javascript">
$(function () {
var ic = new ActiveIC();
ic.connect()
$("#btn_nameplate_clear").click(function () {
$("#manufactor").val("");
$("#system").val("");
$("#customer").val("");
})
$("#btn_nameplate_tmp_load").click(function () {
var def = {
manufactor: "SUNYARD@",
system: "PAYVER50",
customer: "ICBC-ZJ"
}
$("#manufactor").val(def.manufactor);
$("#system").val(def.system);
$("#customer").val(def.customer);
})
$("#btn_nameplate_read").click(function () {
try {
ic.readText(0, 32)
.then(function (def){
def = hexToString( def.data )
$("#manufactor").val(def.substr(0, 8));
$("#system").val(def.substr(8, 8));
$("#customer").val(def.substr(16, 16));
success("返显成功")
})
.catch(function (e) {
alert("返显失败:" + e.msg)
})
} catch (e) {
alert("返显失败:" + e.msg)
}
})
$("#btn_nameplate_tmp_load").click(function () {
var json = localStorage.getItem("tmp")
var def = {
manufactor: "SUNYARD@",
system: "PAYVER50",
customer: "ICBC-ZJ"
}
try {
def = JSON.parse(json)
} catch (e) {
}
$("#manufactor").val(def.manufactor);
$("#system").val(def.system);
$("#customer").val(def.customer);
})
$("#btn_nameplate_tmp_save").click(function () {
var def = {
manufactor: $("#manufactor").val(),
system: $("#system").val(),
customer: $("#customer").val()
}
localStorage.setItem("tmp", JSON.stringify(def))
})
$("#btn_nameplate_release").click(function () {
var def = {
manufactor: $("#manufactor").val(),
system: $("#system").val(),
customer: $("#customer").val()
}
check(def.manufactor, /[\w|@]{8}/, "厂家标记填写错误")
check(def.system, /\w{8}/, "系统信息填写错误")
check(def.customer, /[\w|\|\-|\-]{7,16}/, "客户信息填写错误")
try {
def.customer += " "
def.customer = def.customer.substr(0, 16)
var info = def.manufactor + def.system + def.customer
ic.writeText(0, info).then(function () {
success("发行成功")
}).catch(function (e) {
alert("发行失败:" + e.msg)
});
} catch (e) {
console.log( e )
}
})
$("#btn_clear").click(function () {
$("#path1").val("");
$("#path2").val("");
})
$("#btn_read").click(function () {
ic.readText(0x20, 1)
.then(function (def){
$("#path1").val(def.data);
return ic.readText(0x30, 4)
})
.then(function (def){
$("#path2").val(def.data);
return ic.readText(0x40, 16);
// success("读取成功")
})
.then(function (def){
$("#path3").val(def.data);
return ic.readText(0x50, 4);
// success("读取成功")
})
.then(function (def){
$("#path4").val(def.data);
return ic.readText(0x60, 16);
// success("读取成功")
})
.then(function (def){
$("#path5").val(def.data);
success("读取成功")
})
.catch(function (e) {
alert("读取失败:" + e.msg)
})
})
$("#btn_write").click(function () {
var path1 = $("#path1").val();
if ( path1 != "31"
&& path1 != "32"
&& path1 != "33") {
alert("IC卡属主填写错误")
return
}
var path2 = $("#path2").val();
check(path2, /^([A-Fa-f0-9][A-Fa-f0-9]){4}$/g, "特征字串2填充错误")
var path3 = $("#path3").val();
check(path3, /^([A-Fa-f0-9][A-Fa-f0-9]){16}$/g, "特征字串3填充错误")
var path4 = $("#path4").val();
check(path4, /^([A-Fa-f0-9][A-Fa-f0-9]){4}$/g, "特征字串4填充错误")
var path5 = $("#path5").val();
check(path5, /^([A-Fa-f0-9][A-Fa-f0-9]){16}$/g, "特征字串5填充错误")
ic.writeHex(0x20, path1)
.then(function (def){
return ic.writeHex(0x30, path2)
})
.then(function (def){
return ic.writeHex(0x40, path3)
})
.then(function (def){
return ic.writeHex(0x50, path4)
})
.then(function (def){
return ic.writeHex(0x60, path5)
})
.then(function (def){
success("写入成功")
})
.catch(function (e) {
alert("写入失败:" + e.msg)
})
})
})
</script>
</body>
</html>
-4
View File
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large Load Diff
-26
View File
@@ -1,26 +0,0 @@
var des, sm4;
try {
des = require('./des.js')
} catch (error) {
des = new DES()
}
try {
sm4 = require('./sm4.js')
} catch (error) {
sm4 = SM4
}
var softcrypt = {
CalDES: des.CalDES,
Cal919MAC: des.CalANSI919MAC,
Cal99MAC: des.CalX99MAC,
CalSM4: sm4.SM4CryptECB,
CalSM4MAC: sm4.SM4MACGenerated
}
try {
module.exports = softcrypt
} catch (error) {
}
-318
View File
@@ -1,318 +0,0 @@
var SM4 = {};
(function () {
var SM4_ENCRYPT = 1
var SM4_DECRYPT = 0
function sm4_context() {
this.mode = 0;
this.sk = []
}
function GET_ULONG_BE(n, b, i) {
return (b[i] << 24) | (b[i + 1] << 16) | (b[i + 2]) << 8 | (b[i + 3])
}
function PUT_ULONG_BE(n, b, i) {
b[i] = n >>> 24
b[i + 1] = n >>> 16
b[i + 2] = n >>> 8
b[i + 3] = n
}
function ROTL(x, n) {
var a = (x & 0xFFFFFFFF) << n
var b = x >>> (32 - n)
return a | b
}
var SboxTable = [
[0xd6, 0x90, 0xe9, 0xfe, 0xcc, 0xe1, 0x3d, 0xb7, 0x16, 0xb6, 0x14, 0xc2, 0x28, 0xfb, 0x2c, 0x05],
[0x2b, 0x67, 0x9a, 0x76, 0x2a, 0xbe, 0x04, 0xc3, 0xaa, 0x44, 0x13, 0x26, 0x49, 0x86, 0x06, 0x99],
[0x9c, 0x42, 0x50, 0xf4, 0x91, 0xef, 0x98, 0x7a, 0x33, 0x54, 0x0b, 0x43, 0xed, 0xcf, 0xac, 0x62],
[0xe4, 0xb3, 0x1c, 0xa9, 0xc9, 0x08, 0xe8, 0x95, 0x80, 0xdf, 0x94, 0xfa, 0x75, 0x8f, 0x3f, 0xa6],
[0x47, 0x07, 0xa7, 0xfc, 0xf3, 0x73, 0x17, 0xba, 0x83, 0x59, 0x3c, 0x19, 0xe6, 0x85, 0x4f, 0xa8],
[0x68, 0x6b, 0x81, 0xb2, 0x71, 0x64, 0xda, 0x8b, 0xf8, 0xeb, 0x0f, 0x4b, 0x70, 0x56, 0x9d, 0x35],
[0x1e, 0x24, 0x0e, 0x5e, 0x63, 0x58, 0xd1, 0xa2, 0x25, 0x22, 0x7c, 0x3b, 0x01, 0x21, 0x78, 0x87],
[0xd4, 0x00, 0x46, 0x57, 0x9f, 0xd3, 0x27, 0x52, 0x4c, 0x36, 0x02, 0xe7, 0xa0, 0xc4, 0xc8, 0x9e],
[0xea, 0xbf, 0x8a, 0xd2, 0x40, 0xc7, 0x38, 0xb5, 0xa3, 0xf7, 0xf2, 0xce, 0xf9, 0x61, 0x15, 0xa1],
[0xe0, 0xae, 0x5d, 0xa4, 0x9b, 0x34, 0x1a, 0x55, 0xad, 0x93, 0x32, 0x30, 0xf5, 0x8c, 0xb1, 0xe3],
[0x1d, 0xf6, 0xe2, 0x2e, 0x82, 0x66, 0xca, 0x60, 0xc0, 0x29, 0x23, 0xab, 0x0d, 0x53, 0x4e, 0x6f],
[0xd5, 0xdb, 0x37, 0x45, 0xde, 0xfd, 0x8e, 0x2f, 0x03, 0xff, 0x6a, 0x72, 0x6d, 0x6c, 0x5b, 0x51],
[0x8d, 0x1b, 0xaf, 0x92, 0xbb, 0xdd, 0xbc, 0x7f, 0x11, 0xd9, 0x5c, 0x41, 0x1f, 0x10, 0x5a, 0xd8],
[0x0a, 0xc1, 0x31, 0x88, 0xa5, 0xcd, 0x7b, 0xbd, 0x2d, 0x74, 0xd0, 0x12, 0xb8, 0xe5, 0xb4, 0xb0],
[0x89, 0x69, 0x97, 0x4a, 0x0c, 0x96, 0x77, 0x7e, 0x65, 0xb9, 0xf1, 0x09, 0xc5, 0x6e, 0xc6, 0x84],
[0x18, 0xf0, 0x7d, 0xec, 0x3a, 0xdc, 0x4d, 0x20, 0x79, 0xee, 0x5f, 0x3e, 0xd7, 0xcb, 0x39, 0x48]
]
var FK = [0xa3b1bac6, 0x56aa3350, 0x677d9197, 0xb27022dc];
var CK = [
0x00070e15, 0x1c232a31, 0x383f464d, 0x545b6269,
0x70777e85, 0x8c939aa1, 0xa8afb6bd, 0xc4cbd2d9,
0xe0e7eef5, 0xfc030a11, 0x181f262d, 0x343b4249,
0x50575e65, 0x6c737a81, 0x888f969d, 0xa4abb2b9,
0xc0c7ced5, 0xdce3eaf1, 0xf8ff060d, 0x141b2229,
0x30373e45, 0x4c535a61, 0x686f767d, 0x848b9299,
0xa0a7aeb5, 0xbcc3cad1, 0xd8dfe6ed, 0xf4fb0209,
0x10171e25, 0x2c333a41, 0x484f565d, 0x646b7279
]
function sm4Sbox(n) {
var l = n >>> 4
var r = n % 16
return SboxTable[l][r]
}
function sm4Lt(ka) {
var bb = 0;
var c = 0;
var a = new Uint8Array(4);
var b = new Array(4);
PUT_ULONG_BE(ka, a, 0)
b[0] = sm4Sbox(a[0])
b[1] = sm4Sbox(a[1])
b[2] = sm4Sbox(a[2])
b[3] = sm4Sbox(a[3])
bb = GET_ULONG_BE(bb, b, 0)
c = bb ^ (ROTL(bb, 2)) ^ (ROTL(bb, 10)) ^ (ROTL(bb, 18)) ^ (ROTL(bb, 24))
return c;
}
function sm4F(x0, x1, x2, x3, rk) {
return (x0 ^ sm4Lt(x1 ^ x2 ^ x3 ^ rk))
}
function sm4CalciRK(ka) {
var bb = 0;
var rk = 0;
var a = new Uint8Array(4);
var b = new Array(4);
PUT_ULONG_BE(ka, a, 0)
b[0] = sm4Sbox(a[0]);
b[1] = sm4Sbox(a[1]);
b[2] = sm4Sbox(a[2]);
b[3] = sm4Sbox(a[3]);
bb = GET_ULONG_BE(bb, b, 0)
rk = bb ^ (ROTL(bb, 13)) ^ (ROTL(bb, 23))
return rk;
}
function sm4_setkey(SK, key) {
var MK = new Array(4);
var k = new Array(36);
var i = 0;
MK[0] = GET_ULONG_BE(MK[0], key, 0);
MK[1] = GET_ULONG_BE(MK[1], key, 4);
MK[2] = GET_ULONG_BE(MK[2], key, 8);
MK[3] = GET_ULONG_BE(MK[3], key, 12);
k[0] = MK[0] ^ FK[0]
k[1] = MK[1] ^ FK[1]
k[2] = MK[2] ^ FK[2]
k[3] = MK[3] ^ FK[3]
for (; i < 32; i++) {
k[i + 4] = k[i] ^ (sm4CalciRK(k[i + 1] ^ k[i + 2] ^ k[i + 3] ^ CK[i]))
SK[i] = k[i + 4];
}
}
function sm4_one_round(sk, input, output) {
var i = 0;
var ulbuf = new Array(36);
ulbuf[0] = GET_ULONG_BE(ulbuf[0], input, 0)
ulbuf[1] = GET_ULONG_BE(ulbuf[1], input, 4)
ulbuf[2] = GET_ULONG_BE(ulbuf[2], input, 8)
ulbuf[3] = GET_ULONG_BE(ulbuf[3], input, 12)
while (i < 32) {
ulbuf[i + 4] = sm4F(ulbuf[i], ulbuf[i + 1], ulbuf[i + 2], ulbuf[i + 3], sk[i]);
i++;
}
PUT_ULONG_BE(ulbuf[35], output, 0);
PUT_ULONG_BE(ulbuf[34], output, 4);
PUT_ULONG_BE(ulbuf[33], output, 8);
PUT_ULONG_BE(ulbuf[32], output, 12);
}
function sm4_setkey_enc(ctx, key) {
ctx.mode = SM4_ENCRYPT;
sm4_setkey(ctx.sk, key);
}
function sm4_setkey_dec(ctx, key) {
var i, j;
ctx.mode = SM4_ENCRYPT;
sm4_setkey(ctx.sk, key);
for (i = 0; i < 16; i++) {
j = ctx.sk[31 - i]
ctx.sk[31 - i] = ctx.sk[i]
ctx.sk[i] = j
}
}
function sm4_crypt_ecb(ctx, mode, length, input, output) {
var index = 0;
while (length > 0) {
var oneInput = input.slice(index, index + 16)
var oneOutput = new Uint8Array(16)
sm4_one_round(ctx.sk, oneInput, oneOutput);
for (var i = 0; i < 16; i++) {
output[index + i] = oneOutput[i]
}
index += 16;
length -= 16;
}
}
function sm4_crypt_cbc(ctx, mode, length, iv, input, output) {
var i;
var temp = new Array(16);
var index = 0;
if (mode == SM4_ENCRYPT) {
while (length > 0) {
var oneInput = input.slice(index, index + 16)
var oneOutput = new Array(16)
for (i = 0; i < 16; i++) {
oneOutput[i] = oneInput[i] ^ iv[i]
}
sm4_one_round(ctx.sk, oneOutput, oneOutput);
for (i = 0; i < 16; i++) {
iv[i] = oneOutput[i]
output[index + i] = oneOutput[i]
}
index += 16;
length -= 16;
}
} else /* SM4_DECRYPT */ {
while (length > 0) {
var oneInput = input.slice(index, index + 16)
var oneOutput = new Array(16)
index += 16;
for (i = 0; i < 16; i++) {
temp[i] = oneInput[i]
}
sm4_one_round(ctx.sk, oneInput, oneOutput);
for (i = 0; i < 16; i++) {
oneOutput[i] = oneOutput[i] ^ iv[i]
output[index + i] = oneOutput[i]
}
for (i = 0; i < 16; i++) {
iv[i] = temp[i]
}
index += 16;
length -= 16;
}
}
}
function strfix(str, len) {
var length = len - str.length
while (length-- > 0) {
str = "0" + str
}
return str
}
function HEXStrXOR(str1, str2) {
var buf1 = hex2Array(str1)
var buf2 = hex2Array(str2)
var result = ''
for (var i = 0; i < 16; i++) {
result += strfix((buf1[i] ^ buf2[i]).toString(16).toUpperCase(), 2)
}
return result
}
function hex2Array(str) {
var len = str.length / 2,
substr = '',
result = new Array(len);
for (var i = 0; i < len; i++) {
substr = str.slice(2 * i, 2 * (i + 1))
result[i] = parseInt(substr, 16) || 0
}
return result
}
SM4.SM4CryptECB = function (szData, sCryptFlag, szSM4Key) {
if (szSM4Key.length !== 32) {
console.log("传入密钥[" + szSM4Key + "]长度不为32位");
return "";
}
var len = szData.length
var count = len % 32
if(count !== 0) {
count = 32 - count
len += count
while (count --) {
szData += '0'
}
}
var ctx = new sm4_context()
var lpbKey = hex2Array(szSM4Key)
if (sCryptFlag === SM4_ENCRYPT) {
sm4_setkey_enc(ctx, lpbKey); //加密
} else {
sm4_setkey_dec(ctx, lpbKey); //解密
}
var lpbData = hex2Array(szData)
var pbyCryptResult = new Array(len / 2)
sm4_crypt_ecb(ctx, sCryptFlag, len / 2, lpbData, pbyCryptResult)
var szResult = ''
for (var i = 0; i < len / 2; i++) {
szResult += strfix(pbyCryptResult[i].toString(16), 2).toUpperCase()
}
return szResult;
}
SM4.SM4MACGenerated = function (szData, szSM4Key) {
if (szSM4Key.length !== 32) {
console.log("传入密钥[" + szSM4Key + "]长度不为32位");
return "";
}
var len = szData.length
var count = Math.floor(len / 32)
if (len % 32 !== 0) {
count += 1;
var dvalue = count * 32 - len
while(dvalue--) szData += '0';
len = count * 32
}
var szResult = '', macString = '';
for (var i = 0; i < count; i++) {
macString = szData.slice(32 * i, 32 * (i + 1))
if (i > 0) {
macString = HEXStrXOR(macString, szResult);
}
szResult = SM4.SM4CryptECB(macString, 1, szSM4Key);
}
return szResult
}
})()
try {
module.exports = SM4
} catch (error) {
}
-20
View File
@@ -1,20 +0,0 @@
var CryptoJS = require("crypto-js");
var fHEX = require("crypto-js/format-hex");
var text = CryptoJS.enc.Hex.parse("12345678123456781234567812345678");
var key = CryptoJS.enc.Hex.parse("12345678123456781234567812345678");
function enc(text, key){
var encrypt = CryptoJS.TripleDES.encrypt(text, key, {
mode: CryptoJS.mode.ECB, //CBC模式
// mode: CryptoJS.mode.ECB, //ECB模式
padding: CryptoJS.pad.NoPadding//padding处理
}
);
var encryptData = encrypt.toString(fHEX);//加密完成后,转换成字符串
console.log( encryptData )
return encryptData;
}
enc(text, key)
-1
View File
File diff suppressed because one or more lines are too long
-5
View File
File diff suppressed because one or more lines are too long
-116
View File
@@ -1,116 +0,0 @@
/**
* int 转 byte
* @param i
*/
function intToByte(i) {
var b = i & 0xFF;
var c = 0;
if (b >= 128) {
c = b % 128;
c = -1 * (128 - c);
} else {
c = b;
}
return c;
}
function stringToHex(str){
var val = "";
for (var i = 0; i < str.length; i++) {
var v = str.charCodeAt(i).toString(16);
if ( v.length < 2 ) {
v = "0" + v;
}
val += v;
}
return val
}
function toHex(d) { return ("0"+(Number(d).toString(16))).slice(-2).toUpperCase() }
function mac( hex ) {
if ( ! /^([A-Fa-f0-9][A-Fa-f0-9])+$/.test( hex ) ) {
throw "hex 格式错误"
}
var checkNum = intToByte(0);
var arrBytes = new Array();
for ( var i = 0 ; i < hex.length; i+=2 ) {
var v = intToByte(parseInt(hex[i] + hex[i+1], 16))
arrBytes.push( v )
checkNum = checkNum ^ v;
}
return toHex( checkNum & 0xFF )
}
console.log( mac("FFFF010203EEEECCCC7777223311") )
function xor(d1, d2, d3) {
if ( 32 !== d1.length || 32 !== d2.length || 32 !== d3.length ) {
throw "输入格式错误"
}
var a1 = hexToBytes(d1);
var a2 = hexToBytes(d2);
var a3 = hexToBytes(d3);
var data = [];
for ( var i = 0; i < 16 ; i++){
data[ i ] = a1[ i ] ^ a2[ i ] ^ a3[ i ]
}
return bytesToHex( data )
}
var r = xor("11111111111111111111111111111111", "22222222222222222222222222222222", "33333333333333333333333333333333")
console.log( r )
// Des3
// npm i crypto-js
function hexToBytes(hex) {
for (var bytes = [], c = 0; c < hex.length; c += 2)
bytes.push(parseInt(hex.substr(c, 2), 16));
return bytes;
}
function bytesToHex(bytes) {
for (var hex = [], i = 0; i < bytes.length; i++) {
hex.push((bytes[i] >>> 4).toString(16));
hex.push((bytes[i] & 0xF).toString(16));
}
return hex.join("");
}
// const DES = require('./jssrc/des.js')
// var des = new DES();
// var key = hexToBytes("12345678123456781234567812345678")
// var ret = des.CalDES(hexToBytes("00000000000000000000000000000000"), key);
// console.log( ret )
//
// des = new DES();
// key = hexToBytes("12345678123456781234567812345670")
// ret = des.CalDES(hexToBytes("00000000000000000000000000000000"), key);
// console.log( ret )
//
//
const sm4 = require('./jssrc/sm4.js')
var ret = sm4.SM4CryptECB("00000000000000000000000000000000", 1 , "11111111111111111111111111111111")
console.log( ret )
// const tripledes = require("crypto-js/tripledes");
//
// var value = "123";CryptoJS.enc.Hex.parse("0000000000000000");
// var key = "12345678123456781234567812345678"; CryptoJS.enc.Hex.parse("12345678123456781234567812345678");
//
// var encrypted = tripledes.encrypt(value , key);
// var decrypted = tripledes.decrypt(encrypted, key);
//
// console.log( "encrypted", encrypted.toString('hex') )
// console.log( "decrypted", decrypted )
-4443
View File
File diff suppressed because it is too large Load Diff
-7
View File
@@ -1,7 +0,0 @@
{
"dependencies": {
"crypto-js": "^4.1.1",
"install": "^0.13.0",
"npm": "^9.2.0"
}
}
-55
View File
@@ -1,55 +0,0 @@
.tabs {
overflow: hidden;
width: 100%;
margin: 0;
padding: 0;
list-style: none;
}
.tabs li {
float: left;
margin: 0 -15px 0 0;
}
.tabs a {
float: left;
position: relative;
padding: 0 40px;
height: 0;
line-height: 30px;
text-transform: uppercase;
text-decoration: none;
color: #fff;
border-right: 30px solid transparent;
border-bottom: 30px solid var(--mainColor);
/*border-bottom-color: #777 \9;*/
opacity: .3;
filter: alpha(opacity=30);
}
.tabs a:hover {
border-bottom-color: var(--mainColor);
opacity: 0.5;
filter: alpha(opacity=50);
}
.tabs a:focus {
outline: 0;
}
.tabs .current {
z-index: 3;
border-bottom-color: var(--mainColor);
opacity: 1;
filter: alpha(opacity=100);
}
.tabs-content {
background: #fff;
border-top: 2px solid var(--mainColor);
padding: 1rem 0;
}
.tabs-content h2, #content h3, #content p {
margin: 0 0 15px 0;
}
-19
View File
@@ -1,19 +0,0 @@
$(function (){
var $e = $(".tabs a").first();
$e.addClass("current")
showHideBlock( $e )
function showHideBlock($e){
$(".tabs-content .tab").hide()
var block = ".tabs-content .tab" + "." + $e.attr("name")
$(block).show()
}
$(".tabs a").click(function (){
$(".tabs a").removeClass("current")
$(this).addClass("current")
showHideBlock( $(this) )
})
})
-45
View File
@@ -1,45 +0,0 @@
// 覆盖默认行为
function success(msg){
layx.notice({
title: '成功',
type: 'success',
message: msg
});
}
// 覆盖默认行为
function warning(msg){
layx.notice({
title: '警告',
type: 'warning',
message: msg
});
}
// 覆盖默认行为
function alert(msg){
layx.notice({
title: '错误',
type: 'error',
message: msg
});
}
function check(v, re, msg) {
if (!re.test(v)) {
alert("参数校验失败:" + msg)
throw "参数校验失败"
}
}
function getyyyyMMdd(){
var d = new Date();
var curr_date = d.getDate();
var curr_month = d.getMonth() + 1;
var curr_year = d.getFullYear();
String(curr_month).length < 2 ? (curr_month = "0" + curr_month): curr_month;
String(curr_date).length < 2 ? (curr_date = "0" + curr_date): curr_date;
var yyyyMMdd = curr_year + "" + curr_month +""+ curr_date;
return yyyyMMdd;
}