javascript实现rsa算法(支持微信小程序)

概述:

本代码是本人从c代码上转换成的javascript代码,本人踏踏实实改了一个星期(累死我了),反反复复测试验证通过的。公钥计算快,私钥计算很慢。
在微信小程序上测试验证通过的,和我们常用的文件wxapp_rsa.js对比
1、代码少,才30k左右,而wxapp_rsa.js有400k;
2、功能少了对公钥文件解析(很麻烦,我基本上不会在前端用到),取代直接传密钥的各个部分(公钥指数模,私钥指数模);
3、功能少了base64处理,这功能简单很容易其他地方找到;

测试平台:

已经在如下环境中测试通过,其他平台(浏览器)应该也不会有问题:
1、nodejs中node.exe运行
2、微信小程序

功能代码:

function strRsaCtxParams() {this.keyn;this.keye;this.keyd;this.keybits;
};function rsa_pkcs1_pad(orgdata, mode/*0:0填充,1:F填充, 2:不为0随机数填充*/, bits) {var outData = new Uint8Array(parseInt((bits + 7) / 8));var i = 0;var j = 0;for (i = 0; i < outData.length; i++) {outData[i] = 0;}//return outData;//mode = 1;if (orgdata.length > outData.length - 4) {throw Error('数据长度过长导致不能填充');}if (mode != 0 && mode != 1 && mode != 2) {throw Error('填充模式必须在0,1,2中选择');}outData[0] = 0x00;outData[1] = mode;for (i = 2; i < outData.length - orgdata.length - 1; i++) {if (mode == 0) {outData[i] = 0;} else if (mode == 1) {outData[i] = 0xFF;} else if (mode == 2) {outData[i] = parseInt(Math.random() * 256) & 0xff;if (outData[i] == 0) {/* 简单点,为0改为1 */outData[i] = 1;}}}//console.log("i1 = %d", i);outData[i] = 0;i++;j = 0;while (i < outData.length && j < orgdata.length) {outData[i] = orgdata[j];i++;j++;}//console.log("i2 = %d", i);return outData;
}function rsa_set_key(keyNArray, keyEArray, keyDArray) {var rsaCtxParams = new strRsaCtxParams();//var i = 0;if (keyNArray == null || keyNArray.length <= 0) {throw Error('n的值不能为空');}rsaCtxParams.keybits = CalArrayBits(keyNArray, keyNArray.length);rsaCtxParams.keyn = NN_Decode(keyNArray, keyNArray.length);//console.log("rsaCtxParams.keyn len = %d index0=%d index1=%d index63=%d", rsaCtxParams.keyn.length, rsaCtxParams.keyn[0],  rsaCtxParams.keyn[1], rsaCtxParams.keyn[63]);if (keyEArray != null) {rsaCtxParams.keye = NN_Decode(keyEArray, keyEArray.length);}if (keyDArray != null) {rsaCtxParams.keyd = NN_Decode(keyDArray, keyDArray.length);}return rsaCtxParams;
}function rsa_pub_cal(rsaCtxParams, lpIn) {var m = null;var c = null;var eDigits, nDigits;var outResult = null;var tmpInt = 0;if (rsaCtxParams.keyn == null || rsaCtxParams.keyn.length <= 0) {throw Error('n的值不能为空');}if (rsaCtxParams.keye == null || rsaCtxParams.keye.length <= 0) {throw Error('e的值不能为空');}m = NN_Decode(lpIn, lpIn.length);if (BignumCmp(m, rsaCtxParams.keyn) >= 0) {throw Error('输入数据不能大于等于n');}//console.log("m len = %d", m.length);//printfInts("m", m, m.length);nDigits = NN_Digits(rsaCtxParams.keyn, 0, rsaCtxParams.keyn.length);eDigits = NN_Digits(rsaCtxParams.keye, 0, rsaCtxParams.keye.length);//console.log("nDigits = %d  eDigits = %d", nDigits, eDigits);c = new Array(parseInt(((rsaCtxParams.keybits) + 31) / 32));init_u32array(c, c.length);NN_ModExp(c, m, rsaCtxParams.keye, eDigits, rsaCtxParams.keyn, nDigits, rsaCtxParams);tmpInt = parseInt((rsaCtxParams.keybits + 7) / 8);outResult = new Uint8Array(tmpInt);NN_Encode(outResult, 0, tmpInt, c, 0, nDigits);return outResult;
}function rsa_pri_cal(rsaCtxParams, lpIn) {var m = null;var c = null;var nDigits = 0;var dDigits = 0;var outResult = null;var tmpInt = 0;if (rsaCtxParams.keyn == null || rsaCtxParams.keyn.length <= 0) {throw Error('n的值不能为空');}if (rsaCtxParams.keyd == null || rsaCtxParams.keyd.length <= 0) {throw Error('e的值不能为空');}c = NN_Decode(lpIn, lpIn.length);if (BignumCmp(c, rsaCtxParams.keyn) >= 0) {throw Error('输入数据不能大于等于n');}nDigits = NN_Digits(rsaCtxParams.keyn, 0, rsaCtxParams.keyn.length);dDigits = NN_Digits(rsaCtxParams.keyd, 0, rsaCtxParams.keyd.length);m = new Array(parseInt(((rsaCtxParams.keybits) + 31) / 32));//console.log("pro0");NN_ModExp(m, c, rsaCtxParams.keyd, dDigits, rsaCtxParams.keyn, nDigits, rsaCtxParams);//console.log("pro1");tmpInt = parseInt((rsaCtxParams.keybits + 7) / 8);outResult = new Uint8Array(tmpInt);NN_Encode(outResult, 0, tmpInt, m, 0, nDigits);return outResult;
}function NN_Encode(a, aindex, len, b, bindex, digits) {var t;var j;var i, u;for (i = 0, j = len - 1; i < digits && j >= 0; i++) {t = b[i + bindex];for (u = 0; j >= 0 && u < 32; j--, u += 8) {a[j + aindex] = (t >>> u) & 0xffffffff;}}for (; j >= 0; j--) {a[j + aindex] = 0;}
}function NN_ASSIGN_DIGIT(a, aindex, b, digits) {NN_AssignZero(a, aindex, digits);a[0] = b;
}function DIGIT_2MSB(x) {//(unsigned int)(((x) >> (NN_DIGIT_BITS - 2)) & 3)return ((((x) >>> (32 - 2)) & 3) & 0xffffffff) >>> 0;
}//var testI = 0;function NN_ModExp(a, b, c, cDigits, d, dDigits, rsaCtxParams) {var uPowerLen = parseInt((rsaCtxParams.keybits + 31) / 32);var bPower = new Array(3 * uPowerLen);var t = new Array(uPowerLen);var i = 0, j = 0, s = 0;var ci = 0;var ciBits = 0;init_u32array(bPower, bPower.length);//for (i = 0; i < bPower.length; i++) {//	bPower[i] = 0;//}//console.log("dDigits = %d", dDigits);//printfInts("bPower", bPower, bPower.length);//printfInts("b", b, b.length);//throw Error("11");//console.log("pro2");NN_Assign(bPower, 0, b, 0, dDigits);//printfInts("bPower", bPower, bPower.length);//printfInts("b", b, b.length);//throw Error("223");//console.log("pro3");NN_ModMult(bPower, uPowerLen, bPower, 0, b, 0, d, 0, dDigits, rsaCtxParams);//console.log("pro4");NN_ModMult(bPower, uPowerLen * 2, bPower, uPowerLen, b, 0, d, 0, dDigits, rsaCtxParams);//NN_Assign(bPower, uPowerLen, b, 0, dDigits);//NN_Assign(bPower, uPowerLen * 2, b, 0, dDigits);//printfIntsIndex("bPower0", bPower, 0, uPowerLen);//printfIntsIndex("bPower1", bPower, uPowerLen, uPowerLen);//printfIntsIndex("bPower2", bPower, uPowerLen * 2, uPowerLen);//console.log("pro5");NN_ASSIGN_DIGIT(t, 0, 1, dDigits);//console.log("pro6");cDigits = NN_Digits(c, 0, cDigits);//console.log("pro7");for (i = cDigits - 1; i >= 0; i--) {//console.log("pro8");ci = c[i];ciBits = 32;if (i == (cDigits - 1)) {while (0 == DIGIT_2MSB(ci)) {//console.log("pro9");ci <<= 2;ci &= 0xffffffff;//ciBits -= 2;ciBits = bn_u32_minus(ciBits, 2);}}for (j = 0; j < ciBits; j += 2, ci = (ci << 2) & 0xffffffff) {//console.log("pro10");/* Compute t = t^4 * b^s mod d, where s = two MSB's of ci. */NN_ModMult(t, 0, t, 0, t, 0, d, 0, dDigits, rsaCtxParams);//console.log("pro11");NN_ModMult(t, 0, t, 0, t, 0, d, 0, dDigits, rsaCtxParams);//console.log("pro12");s = DIGIT_2MSB(ci);//console.log("pro13");if ((s) != 0) {//console.log("pro14");//testI++;//console.log("testI = %d s = %d dDigits = %d", testI, s, dDigits);/*if (testI >= 412) {printfInts("t", t, 129);printfInts("d", d, 128);printfIntsIndex("bPower0", bPower, 0, 128);printfIntsIndex("bPower1", bPower, uPowerLen, 128);printfIntsIndex("bPower2", bPower, uPowerLen * 2, 128);exit(0);}*/NN_ModMult(t, 0, t, 0, bPower, (s - 1) * uPowerLen, d, 0, dDigits, rsaCtxParams);//console.log("pro15");}}}NN_Assign(a, 0, t, 0, dDigits);//printfInts("a", a, a.length);//printfInts("b", b, b.length);//printfInts("c", c, c.length);//printfInts("t", t, t.length);
}function bn_u32_compare(uint1, uint2) {uint1 &= 0xffffffff;uint2 &= 0xffffffff;if ((uint1 & 0x80000000) == 0 && (uint2 & 0x80000000) == 0) {return uint1 > uint2 ? 1 : (uint1 == uint2 ? 0 : (-1));}if ((uint1 & 0x80000000) != 0 && (uint2 & 0x80000000) != 0) {uint1 &= 0x7fffffff;uint2 &= 0x7fffffff;return uint1 > uint2 ? 1 : (uint1 == uint2 ? 0 : (-1));}if ((uint1 & 0x80000000) != 0) {return 1;} else {return -1;}
}function bn_u32_add(add1, add2) {var i = 0;var tmp = 0;var result = 0;for (i = 0; i < 4; i++) {tmp = ((add1 >>> (i * 8)) & 0xff) + ((add2 >>> (i * 8)) & 0xff) + tmp;result |= ((tmp & 0xff) << (i * 8));tmp = tmp >>> 8;}return result & 0xffffffff;
}function bn_u32_minus(minuend, subtractor) {var a = (minuend & 0xffffffff) >>> 0;var b = (subtractor & 0xffffffff) >>> 0;return (a - b) & 0xffffffff;
}function NN_ModMult(a, aindex, b, bindex, c, cindex, d, dindex, digits, rsaCtxParams) {var t = new Array(2 * parseInt((rsaCtxParams.keybits + 31) / 32));init_u32array(t, t.length);//console.log("pp0");NN_Mult(t, 0, b, bindex, c, cindex, digits, rsaCtxParams);//printfIntsIndex("t", t, 0, 128);//printfIntsIndex("b", b, bindex, 128);//printfIntsIndex("c", c, cindex, 128);//console.log("pp1");NN_Mod(a, aindex, t, 0, 2 * digits, d, dindex, digits, rsaCtxParams);
}function NN_Mod(a, aindex, b, bindex, bDigits, c, cindex, cDigits, rsaCtxParams) {//NN_DIGIT t[2 * MAX_NN_DIGITS];var t = new Array(2 * parseInt((rsaCtxParams.keybits + 31) / 32));init_u32array(t, t.length);NN_Div(t, 0, a, aindex, b, bindex, bDigits, c, cindex, cDigits, rsaCtxParams);
}function NN_DigitBits(a) {var i;for (i = 0; i < 32; i++, a = ((a >>> 1) & 0xffffffff)) {if (a == 0) {break;}}return (i);
}function NN_LShift(a, aindex, b, bindex, c, digits) {var temp, carry = 0;var tmpbindex = 0;var tmpaindex = 0;var t;if (c < 32 && digits != 0) {t = 32 - c;do {temp = b[tmpbindex + bindex];//b++;tmpbindex++;//*a = (temp << c) | carry;a[tmpaindex + aindex] = ((temp << c) | carry) & 0xffffffff;//a++;tmpaindex++;carry = (c != 0 ? (temp >>> t) : 0) & 0xffffffff;digits--;if (digits == 0) {break;}} while (true);}return (carry) & 0xffffffff;
}function NN_RShift(a, aindex, b, bindex, c, digits) {var temp = 0,carry = 0;var tmpbindex = 0;var tmpaindex = 0;var t = 0;if (c < 32 && digits != 0) {//if(digits) {t = 32 - c;do {digits--;//temp = *(b+digits);temp = b[digits + bindex];//*(a+digits) = ((temp >> c) | carry);a[digits + aindex] = ((temp >>> c) | carry) & 0xffffffff;carry = (c != 0 ? (temp << t) : 0) & 0xffffffff;} while (digits != 0);}return ((carry) & 0xffffffff) >>> 0;
}function TO_HIGH_HALF(x) {return ((x << 16) & 0xffffffff) >>> 0;
}function subdigitmult(a, aindex, b, bindex, c, d, dindex, digits) {var borrow = 0,thigh = 0,tlow = 0;var i = 0;var arr = new Array(2);borrow = 0;if (c != 0) {for (i = 0; i < digits; i++) {//function dmult(a, b, high, highindex, low, lowindex)//dmult(c, d[i], &thigh, &tlow);arr[0] = thigh;arr[1] = tlow;dmult(c, d[i + dindex], arr, 0, arr, 1);thigh = arr[0];tlow = arr[1];//a[i] = b[i] - borrow;a[i + aindex] = bn_u32_minus(b[i + bindex], borrow);//if((a[i]) > (MAX_NN_DIGIT - borrow)) {if (bn_u32_compare(a[i + aindex], bn_u32_minus(0xffffffff, borrow)) > 0) {borrow = 1;} else {borrow = 0;}//a[i] -= tlow;a[i + aindex] = bn_u32_minus(a[i + aindex], tlow);//if((a[i]) > (MAX_NN_DIGIT - tlow)) {if (bn_u32_compare(a[i + aindex], bn_u32_minus(0xffffffff, tlow)) > 0) {//borrow++;borrow = bn_u32_add(borrow, 1);}//borrow += thigh;borrow = bn_u32_add(borrow, thigh);}}return (borrow) & 0xffffffff;
}function NN_Cmp(a, aindex, b, bindex, digits) {if (digits != 0) {do {digits--;if ((a[digits + aindex] >>> 16) > (b[digits + bindex] >>> 16)) {return 1;}if ((a[digits + aindex] >>> 16) < (b[digits + bindex] >>> 16)) {return -1;}if ((a[digits + aindex] & 0xffff) > (b[digits + bindex] & 0xffff)) {return 1;}if ((a[digits + aindex] & 0xffff) < (b[digits + bindex] & 0xffff)) {return -1;}//if(*(a+digits) > *(b+digits))//	return(1);//if(*(a+digits) < *(b+digits))//	return(-1);} while (digits != 0);}return (0);
}function NN_Sub(a, aindex, b, bindex, c, cindex, digits) {var temp = 0,borrow = 0;var tmpaindex = 0,tmpbindex = 0,tmpcindex = 0;if (digits != 0)do {//temp = (*b) - borrow;temp = bn_u32_minus(b[tmpbindex + bindex], borrow);//b++;//b = bn_u32_add(b, 1);tmpbindex++;//if(temp == MAX_NN_DIGIT) {if (bn_u32_compare(temp, 0xffffffff) == 0) {//temp = MAX_NN_DIGIT - (*c);temp = bn_u32_minus(0xffffffff, c[tmpcindex + cindex]);//c++;tmpcindex++;} else {//temp -= (*c);temp = bn_u32_minus(temp, c[tmpcindex + cindex]);//if((temp) > (MAX_NN_DIGIT - (*c))) {if (bn_u32_compare(temp, bn_u32_minus(0xffffffff, c[tmpcindex + cindex])) > 0) {borrow = 1;} else {borrow = 0;}//c++;tmpcindex++;}//*a = temp;a[tmpaindex + aindex] = temp & 0xffffffff;//a++;tmpaindex++;digits--;if (digits == 0) {break;}} while (true);return (borrow);
}//var test2 = 0;
//var testI = 0;
function NN_Div(a, aindex, b, bindex, c, cindex, cDigits, d, dindex, dDigits, rsaCtxParams) {//NN_DIGIT ai, cc[2*MAX_NN_DIGITS+1], dd[MAX_NN_DIGITS], s;//NN_DIGIT t[2], u, v, *ccptr;//NN_HALF_DIGIT aHigh, aLow, cHigh, cLow;//int i;//unsigned int ddDigits, shift;var cc = new Array(2 * parseInt((rsaCtxParams.keybits + 31) / 32) + 1);var dd = new Array(2 * parseInt((rsaCtxParams.keybits + 31) / 32));var t = new Array(2);var ddDigits = 0;var shift = 0;var s, u, v;var ai;var cHigh, cLow, aHigh, aLow;var i = 0;//var ccptrindex = 0;init_u32array(cc, cc.length);init_u32array(dd, dd.length);NN_AssignZero(dd, 0, dd.length);ddDigits = NN_Digits(d, dindex, dDigits);if (ddDigits == 0) {return;}shift = 32 - NN_DigitBits(d[dindex + ddDigits - 1]);//console.log("shift = %d", shift);NN_AssignZero(cc, 0, ddDigits);cc[cDigits] = NN_LShift(cc, 0, c, 0, shift, cDigits);//console.log("cc[cDigits] = %d", cc[cDigits]);NN_LShift(dd, 0, d, 0, shift, ddDigits);s = dd[ddDigits - 1];//console.log("s = %d", s);//printfInts("cc", cc, cc.length);//printfInts("dd", dd, dd.length);//throw Error("111");NN_AssignZero(a, aindex, cDigits);//throw Error("11222");//test2 = 0;for (i = cDigits - ddDigits; i >= 0; i--) {test2++;//if (testI >= 412) {//	console.log("test2 = %d", test2);//}if (bn_u32_compare(s, 0xffffffff) == 0) {ai = (cc[i + ddDigits]) & 0xffffffff;} else {s = bn_u32_add(s, 1);cHigh = HIGH_HALF(s);cLow = LOW_HALF(s);t[0] = cc[i + ddDigits - 1];t[1] = cc[i + ddDigits];//if (testI >= 412 && test2 >= 13) console.log("t10 = %d %d", t[0], t[1]);if (cHigh == 0xffff) {aHigh = HIGH_HALF(t[1]);//if (testI >= 412 && test2 >= 13) console.log("aHigh1=%d", aHigh);} else {aHigh = parseInt((t[1] >>> 0) / ((cHigh >>> 0) + 1));//if (testI >= 412 && test2 >= 13) console.log("aHigh2=%d", aHigh);}u = ((aHigh >>> 0) * (cLow >>> 0)) & 0xffffffff;v = ((aHigh >>> 0) * (cHigh >>> 0)) & 0xffffffff;//if (testI >= 412 && test2 >= 13) console.log("u = %d v = %d aHigh = %d cLow = %d cHigh = %d", u, v, aHigh, cLow, cHigh);//if (testI >= 412 && test2 >= 13) console.log("t9 = %d %d", t[0], t[1]);t[0] = bn_u32_minus(t[0], TO_HIGH_HALF(u));//if (testI >= 412 && test2 >= 13) console.log("t91 = %d %d u = %d", t[0], t[1], u);if (bn_u32_compare(t[0], bn_u32_minus(0xffffffff, TO_HIGH_HALF(u))) > 0) {t[1] = bn_u32_minus(t[1], 1);}//if (testI >= 412 && test2 >= 13) console.log("t8 = %d %d", t[0], t[1]);//if (testI >= 412 && test2 >= 13) console.log("t[0] = %d t[1] = %d", t[0], t[1]);t[1] = bn_u32_minus(t[1], HIGH_HALF(u));//if (testI >= 412 && test2 >= 13) console.log("t[0] = %d t[1] = %d", t[0], t[1]);t[1] = bn_u32_minus(t[1], v);//if (testI >= 412 && test2 >= 13) console.log("t[0] = %d t[1] = %d", t[0], t[1]);//eeeek;//if (testI >= 412 && test2 >= 13) console.log("t7 = %d %d cHigh = %d, cLow = %d bn_u32_compare(t[0], cLow) = %d", t[0], t[1], cHigh, cLow, bn_u32_compare(t[0], cLow));while (bn_u32_compare(t[1], cHigh) > 0 || (bn_u32_compare(t[1], cHigh) == 0 && bn_u32_compare(t[0], TO_HIGH_HALF(cLow)) >= 0)) {//if (testI >= 412 && test2 >= 13) {//	console.log("rd t[0] = %d t[1] = %d cLow = %d cHigh = %d", t[0], t[1], cLow, cHigh);//	throw Error("");//}t[0] = bn_u32_minus(t[0], TO_HIGH_HALF(cLow));if (bn_u32_compare(t[0], bn_u32_minus(0xffffffff, TO_HIGH_HALF(cLow))) > 0) {t[1] = bn_u32_minus(t[1], 1);}t[1] = bn_u32_minus(t[1], cHigh);aHigh = bn_u32_add(aHigh, 1);}//if (testI >= 412 && test2 >= 13)console.log("t6 = %d %d cHigh = %d, cLow = %d", t[0], t[1], cHigh, cLow);if (bn_u32_compare(cHigh, 0xffff) == 0) {aLow = LOW_HALF(t[1]) & 0xffffffff;//console.log("aLow1 = %d ", aLow);} else {//aLow = parseInt((((TO_HIGH_HALF (t[1]) + HIGH_HALF (t[0])) >>> 0) & 0xffffffff) / bn_u32_add(cHigh, 1));aLow = (TO_HIGH_HALF(t[1]) >>> 0) + ((HIGH_HALF(t[0]) & 0xffffffff) >>> 0);aLow = parseInt(aLow / bn_u32_add(cHigh, 1)) & 0xffffffff;aLow &= 0xffffffff;//console.log("aLow2 = %d ", aLow);}u = ((aLow >>> 0) * (cLow >>> 0)) & 0xffffffff;v = ((aLow >>> 0) * (cHigh >>> 0)) & 0xffffffff;//(*t) -= u;//console.log("t5 = %d %d u = %d aLow = %d cLow = %d cHigh = %d", t[0], t[1], u, aLow, cLow, cHigh);t[0] = bn_u32_minus(t[0], u);//console.log("t4 = %d %d", t[0], t[1]);//if ((*t) > (MAX_NN_DIGIT - u)) {if (bn_u32_compare(t[0], bn_u32_minus(0xffffffff, u)) > 0) {//t[1]--;t[1] = bn_u32_minus(t[1], 1);}//console.log("t3 = %d %d", t[0], t[1]);//(*t) -= TO_HIGH_HALF (v);t[0] = bn_u32_minus(t[0], TO_HIGH_HALF(v));//console.log("t2 = %d %d", t[0], t[1]);//if ((*t) > (MAX_NN_DIGIT - TO_HIGH_HALF (v))) {if (bn_u32_compare(t[0], bn_u32_minus(0xffffffff, TO_HIGH_HALF(v))) > 0) {//t[1]--;t[1] = bn_u32_minus(t[1], 1);}//console.log("t1 = %d %d", t[0], t[1]);//*(t+1) -= HIGH_HALF (v);t[1] = bn_u32_minus(t[1], HIGH_HALF(v));//console.log("t0 = %d %d", t[0], t[1]);//console.log("ai1=%d aHigh = %d aLow = %d t[0] = %d t[1] = %d", ai, aHigh, aLow, t[0], t[1]);//while ((*(t+1) > 0) || ((*(t+1) == 0) && (*t) >= s)) {while (bn_u32_compare(t[1], 0) > 0 || (t[1] == 0 && bn_u32_compare(t[0], s) >= 0)) {//(*t) -= s;t[0] = bn_u32_minus(t[0], s);//if ((*t) > (MAX_NN_DIGIT - s)) {if (bn_u32_compare(t[0], bn_u32_minus(0xffffffff, s)) > 0) {t[1]--;}//aLow++;aLow = bn_u32_add(aLow, 1);}//ai = TO_HIGH_HALF (aHigh) + aLow;ai = bn_u32_add(TO_HIGH_HALF(aHigh), aLow);//console.log("ai0=%d aHigh = %d aLow = %d", ai, aHigh, aLow);//s--;s = bn_u32_minus(s, 1);//console.log("cHigh = %d cLow = %d", cHigh, cLow);//console.log("s = %d ai = %d t[0] = %d t[1] = %d cHigh = %d cLow = %d aHigh = %d aLow = %d u = %d v = %d", //	s, ai, t[0], t[1], cHigh, cLow, aHigh, aLow, u, v);//cc[i+ddDigits] -= subdigitmult(&cc[i], &cc[i], ai, dd, ddDigits);//printfIntsIndex("cc", cc, 0, cc.length);//printfIntsIndex("dd", dd, 0, dd.length);//console.log("ai = %d ddDigits = %d i = %d", ai, ddDigits, i);cc[i + ddDigits] = bn_u32_minus(cc[i + ddDigits], subdigitmult(cc, i, cc, i, ai, dd, 0, ddDigits));//console.log("cc[i+ddDigits] = %d", cc[i+ddDigits]);//printfIntsIndex("cc", cc, 0, cc.length);//printfIntsIndex("dd", dd, 0, dd.length);//console.log("ddDigits = %d", ddDigits);//testI++//console.log("testI = %d", testI);//console.log("NN_Cmp(cc, i, dd, 0, ddDigits) = %d", NN_Cmp(cc, i, dd, 0, ddDigits));//if (testI > 2) {//throw Error("988");//}//console.log("testI = %d", testI);while (cc[i + ddDigits] != 0 || NN_Cmp(cc, i, dd, 0, ddDigits) >= 0) {//	console.log("0 cc[i+ddDigits] = %d ai\n", cc[i+ddDigits]);ai = bn_u32_add(ai, 1);cc[i + ddDigits] = bn_u32_minus(cc[i + ddDigits], NN_Sub(cc, i, cc, i, dd, 0, ddDigits));//console.log("1 cc[i+ddDigits] = %d ai\n", cc[i+ddDigits]);//console.log("ai");//throw Error("9612332");}a[i + aindex] = ai & 0xffffffff;//throw Error("9632");}}//throw Error("987412");NN_AssignZero(b, bindex, dDigits);NN_RShift(b, bindex, cc, 0, shift, ddDigits);//console.log("shift = %d ddDigits = %d", shift, ddDigits);//printfIntsIndex("b", b, bindex, ddDigits);//throw Error("888");
}//var testi = 0;
function NN_Mult(a, aindex, b, bindex, c, cindex, digits, rsaCtxParams) {var t = new Array(2 * parseInt((rsaCtxParams.keybits + 31) / 32));var dhigh = 0xffffffff >>> 0,dlow = 0xffffffff >>> 0,carry = 0xffffffff >>> 0;var bDigits, cDigits, i, j;var tmpAr = new Array(2);init_u32array(t, t.length);init_u32array(tmpAr, tmpAr.length);//printfIntsIndex("a", a, aindex, parseInt((rsaCtxParams.keybits + 31) / 32));//printfIntsIndex("b", b, bindex, parseInt((rsaCtxParams.keybits + 31) / 32));//printfIntsIndex("c", c, cindex, parseInt((rsaCtxParams.keybits + 31) / 32));//throw Error("9988");tmpAr[0] = 0xffffffff >>> 0;tmpAr[1] = 0xffffffff >>> 0;for (i = 0; i < t.length; i++) {t[i] = 0xffffffff >>> 0;}NN_AssignZero(t, 0, t.length);bDigits = NN_Digits(b, bindex, digits);cDigits = NN_Digits(c, cindex, digits);for (i = 0; i < bDigits; i++) {carry = 0;if (b[i + bindex] != 0) {for (j = 0; j < cDigits; j++) {tmpAr[0] = dhigh;tmpAr[1] = dlow;//console.log("%d %d", b[i + bindex], c[j + cindex]);dmult(b[i + bindex], c[j + cindex], tmpAr, 0, tmpAr, 1);dhigh = tmpAr[0];dlow = tmpAr[1];//*(t+(i+j)) = *(t+(i+j)) + carry;//console.log("0t%d=%d dlow = %d dhigh = %d carry = %d", i + j, t[i + j], dlow, dhigh, carry);//testi++;//if (testi > 1) {//	throw Error("ll");//}t[i + j] += carry;t[i + j] &= 0xffffffff;//console.log("1t%d=%d dlow = %d dhigh = %d carry = %d", i + j, t[i + j], dlow, dhigh, carry);//if((*(t+(i+j))) < carry) {//if (t[i + j] < carry) {if (bn_u32_compare(t[i + j], carry) < 0) {carry = 1;} else {carry = 0;}//*(t+(i+j)) += dlow;t[i + j] += dlow;t[i + j] &= 0xffffffff;//console.log("2t%d=%d dlow = %d dhigh = %d carry = %d", i + j, t[i + j], dlow, dhigh, carry);//if((*(t+(i+j))) < dlow) {//if (t[i + j] < dlow) {if (bn_u32_compare(t[i + j], dlow) < 0) {//console.log("carry add");carry++;}carry += dhigh;carry &= 0xffffffff}//throw Error("aaa");}//*(t+(i+cDigits)) += carry;t[i + cDigits] += carry;t[i + cDigits] &= 0xffffffff;}//printfIntsIndex("t", t, 0, t.length);//throw Error("9986");NN_Assign(a, 0, t, 0, 2 * digits);//printfIntsIndex("a", a, aindex, parseInt((rsaCtxParams.keybits + 31) / 32));//printfIntsIndex("b", b, bindex, parseInt((rsaCtxParams.keybits + 31) / 32));//printfIntsIndex("c", c, cindex, parseInt((rsaCtxParams.keybits + 31) / 32));//throw Error("3356");
}function LOW_HALF(val) {return val & 0xffff;
}function HIGH_HALF(val) {return (val >>> 16) & 0xffff;
}function init_u32array(array, len) {var i = 0;for (i = 0; i < len; i++) {array[i] = 0xffffffff >>> 0;}
}function dmult(a, b, high, highindex, low, lowindex) {var al = 0xffffffff >>> 0;var ah = 0xffffffff >>> 0;var bl = 0xffffffff >>> 0;var bh = 0xffffffff >>> 0;var m1 = 0xffffffff >>> 0;var m2 = 0xffffffff >>> 0;var m = 0xffffffff >>> 0;var ml = 0xffffffff >>> 0;var mh = 0xffffffff >>> 0;var carry = 0xffffffff >>> 0;carry = 0;al = LOW_HALF(a);ah = HIGH_HALF(a);bl = LOW_HALF(b);bh = HIGH_HALF(b);low[lowindex] = (al * bl) & 0xffffffff;high[highindex] = (ah * bh) & 0xffffffff;//console.log("low[lowindex] = %d high[highindex] = %d", low[lowindex], high[highindex]);m1 = (al * bh) & 0xffffffff;m2 = (ah * bl) & 0xffffffff;m = (m1 + m2) & 0xffffffff;if (bn_u32_compare(m, m1) < 0) {carry = (1 << 16) & 0xffffffff; //(NN_DIGIT_BITS / 2);}ml = (m & 0xffff) << 16; //(NN_DIGIT_BITS / 2);mh = (m >> 16) & 0xffff; //(NN_DIGIT_BITS / 2);low[lowindex] += ml;if (bn_u32_compare(low[lowindex], ml) < 0) {carry = (carry + 1) & 0xffffffff;}high[highindex] += (carry + mh);low[lowindex] &= 0xffffffff;high[lowindex] &= 0xffffffff;
}function NN_AssignZero(a, aindex, digits) {var tmpaindex = 0;if (digits != 0) {do {//*a++ = 0;//(*a) = 0;a[tmpaindex + aindex] = 0;//a++;tmpaindex++;digits--;if (digits == 0) {break;}} while (true);}
}function NN_Assign(a, aindex, b, bindex, digits) {var tmpaindex = 0;var tmpbindex = 0;if (digits != 0) {/*do {*a++ = *b++;}while(--digits);*/do {a[tmpaindex + aindex] = b[tmpbindex + bindex];//a++;//b++;tmpaindex++;tmpbindex++;digits--;if (digits == 0) {break;}} while (true);}
}function printfInts(title, data, len) {printfIntsIndex(title, data, 0, len);/*var i = 0;for (i = 0; i < len; i++) {console.log("%d %s %d", i, title == null ? "":title, data[i]);}*/
}function printfIntsIndex(title, data, index, len) {var i = 0;for (i = 0; i < len; i++) {console.log("%d %s %d", i, title == null ? "" : title, data[i + index]);}
}function NN_Digits(a, aindex, len) {var i = 0;for (i = len - 1; i >= 0; i--) {if (a[i + aindex] != 0) {return i + 1;}}return i;
}function BignumCmp(a, b) {var amax = a.length - 1;var bmax = b.length - 1;var i = (amax > bmax ? amax : bmax);var aval = 0;var bval = 0;while (i) {aval = i > amax ? 0 : a[i];bval = i > bmax ? 0 : b[i];if (((aval >> 16) & 0xffff) < ((bval >> 16) & 0xffff)) {return -1;}if (((aval >> 16) & 0xffff) > ((bval >> 16) & 0xffff)) {return 1;}if ((aval & 0xffff) < (bval & 0xffff)) {return -1;}if ((aval & 0xffff) > (bval & 0xffff)) {return 1;}i--;}return 0;
}function NN_Decode(bytesArray, len) {var bits = CalArrayBits(bytesArray, len);var i = 0;var j = 0;var outArray = new Array(parseInt((bits + 31) / 32));init_u32array(outArray, outArray.length);for (i = 0; i < outArray.length; i++) {j = bytesArray.length - (i + 1) * 4;//console.log("j = " + j);if (j >= 0) {outArray[i] = ((parseInt(bytesArray[j]) & 0xff) << 24) |((parseInt(bytesArray[j + 1]) & 0xff) << 16) |((parseInt(bytesArray[j + 2]) & 0xff) << 8) |((parseInt(bytesArray[j + 3]) & 0xff) << 0);} else {outArray[i] = 0;if (j + 1 >= 0) {outArray[i] |= ((parseInt(bytesArray[j + 1]) & 0xff) << 16);}if (j + 2 >= 0) {outArray[i] |= ((parseInt(bytesArray[j + 2]) & 0xff) << 8);}if (j + 3 >= 0) {outArray[i] |= ((parseInt(bytesArray[j + 3]) & 0xff) << 0);}}}return outArray;
}function CalArrayBits(arrayData, len) {var i = 0;var j = 0;for (i = 0; i < len; i++) {if (arrayData[i] != 0) {j = -1;break;}}if (j >= 0) {return 0;}for (j = 0; j < 8; j++) {if ((arrayData[i] & (0x80 >>> j)) != 0) {break;}}return 8 - j + (len - i - 1) * 8;
}function rsa_hex_to_array(hexStrIn) {var i = 0;var cnt = 0;var ele = 0;var bytesArray = null;cnt = 0;for (i = 0; i < hexStrIn.length; i++) {ele = hexStrIn.charCodeAt(i);if (ele >= 48 && ele < 48 + 10) {cnt++;}if (ele >= 65 && ele < 65 + 6) {cnt++;}if (ele >= 97 && ele < 97 + 6) {cnt++;}}bytesArray = new Uint8Array(parseInt((cnt + 1) / 2));cnt = 0;for (i = 0; i < hexStrIn.length; i++) {ele = hexStrIn.charCodeAt(i);if (ele >= 48 && ele < 48 + 10) {ele -= 48;cnt++;} else if (ele >= 65 && ele < 65 + 6) {ele = ele - 65 + 10;cnt++;} else if (ele >= 97 && ele < 97 + 6) {ele = ele - 97 + 10;cnt++;} else {continue;}if ((cnt % 2) == 1) {bytesArray[parseInt((cnt - 1) / 2)] = (ele << 4) & 0xF0;} else {bytesArray[parseInt((cnt - 1) / 2)] |= ele;}}return bytesArray;
}function rsa_hex_to_str(data, len) {var sha256_hex_digits = "0123456789abcdef";var output = new String();var i = 0;//console.log("ou1t = " + output);for (i = 0; i < len; i++) {//  console.log("out = " + output);output += sha256_hex_digits.charAt((data[i] >>> 4) & 0x0f);output += sha256_hex_digits.charAt((data[i]) & 0x0f);}return output;
}module.exports = {rsa_set_key: rsa_set_key,rsa_pub_cal: rsa_pub_cal,rsa_pri_cal: rsa_pri_cal,rsa_hex_to_array: rsa_hex_to_array,rsa_hex_to_str: rsa_hex_to_str,rsa_pkcs1_pad:rsa_pkcs1_pad
}

测试代码:

如下在微信小程序中测试验证

var js_rsa = require('../../crypto/rsa.js');
testRsa() {var rsaCtx = null;var keyN = "BEC631E3067608D5065846573408462E4912D5EA343F0FB45DB7F2A1673D5A6D070DE518EBD4420A44E32188313A8B3321FFFC981FEA277BA833E224B9B21A036CE102047DFCBB0F4907EB670C9603E9FD9753681AA74873F47765B03B57E5EB184F4BAB576E4C03FAC8261A560B3EC79EBAFA92DE644362C8D79A7AD858F06CD3DA850ED467F0168B2FB49455A01CCE950ED110C78A90163B315D9C96368AE78F75B0813BEA33B50DFCDCF61D14AF8EB1313A53E3F90C43324EFB315D1FEC64851517C0068257953EE066F305410B2D729753E8D0F7F6D7089B89986B3A9A6109BCB66D4D1FFFF1DFFB347CE0C04019473FC88FA94C4C629A25460BFA900291";var keyD = "6D26C6FA470317D0927DC559358B1A647728D0BDDCC0CC027DB0B6A10489C50826861BB363932169F0BA27C05DB24A5CAA3265DAC03FDFF14F6EC8100D334AD0F4E5D49AAF5EFFC4221BE6E321FF5F23ED153D028E6571FDEE3CB630DBF351B86E43485F337A07022BE5826F85159008F4D7B4707DCFCE02623981C891AA697C4D746DD007330F697F8739392E9001D4FC2993C5E78D1A283C38AAED24EF4C672A1C4E72B2781759080CAE8383EEB69C8BC232360850FEBEF9D862DBC7225A9FE13F98F6BD072C7A027DEA9F9C9CDAB4D3F5F37B03B2375DA9BEF8CF1AD3CCB4C24B236685DDC82F10BA9584FA9A34D545B528B213675E969D7CA3839418AB95";var keyE = "010001";var txt = "00888888889999999999999AAAAAAAAABBBBBBBBCEDFFFFFFFFFFFFFFFFFFFFFFFFF966666666666666666666666666666666666666666666666666633333333333333333333333333333333300000000000000000000000666EEEEEEEEEEEEEEEEEEEEEEFFFFFFFFFFFFFFFFFFFDDDDDDDDDDDDBBBBBBBBBBBBBBBBBCCCCCCCCCCCCCCCCCCCCCCCCCAAAAAAAAAAAAAAAAAAAAAAAAAA88888888644444444444777777777777777799999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999555555555555555555555555555555555555555522222222222222222222222222222222222222";var result, result2;var tmpdata = null;rsaCtx = js_rsa.rsa_set_key(js_rsa.rsa_hex_to_array(keyN), js_rsa.rsa_hex_to_array(keyE), js_rsa.rsa_hex_to_array(keyD));result = js_rsa.rsa_pub_cal(rsaCtx, js_rsa.rsa_hex_to_array(txt));console.log("rsa_pub_cal:" + js_rsa.rsa_hex_to_str(result, result.length));result2 = js_rsa.rsa_pri_cal(rsaCtx, result);console.log("rsa_pri_cal:" + js_rsa.rsa_hex_to_str(result2, result2.length));/* 下面的用pkcs1填充然后公玥计算,可以在后台用对应的私玥解密出来 */tmpdata = js_rsa.rsa_pkcs1_pad(js_rsa.rsa_hex_to_array("1122334455667788"), 2, rsaCtx.keybits);result = js_rsa.rsa_pub_cal(rsaCtx, tmpdata);console.log("rsa_pub_cal:" + js_rsa.rsa_hex_to_str(result, result.length));result2 = js_rsa.rsa_pri_cal(rsaCtx, result);console.log("rsa_pri_cal:" + js_rsa.rsa_hex_to_str(result2, result2.length));},

测试结果:

rsa_pub_cal:2fac299b8f780e12a331a73ca61551deb3cd41127d76d5c855624eb6d02eac9581be481fec0ec3c882e1cb26de31dffa19a689cd36a5255021fc44ab3399385f91db7352701bca8f1955237085ef2e0d216831653367799cddaf8c4b77611287fedfcc93de93d3c28461d29d609322f1b1d1b4543d1cc2921b50253fd1da15f9174a94ff8cb70cab180d56d00dd4f28e3a914abc28f770623af2eed11c560a26fe1187050038da28ad897068373b5bdfe14fb44905fcdc0cbeefde21a155ecf238423a2c967b710cbab39a235a6385c285535707c20bab1ae7601def49959cd42aa700389423fdcf17f2c42a00f2b1da8320586d24ef5d5dfe92cc203047020b
rsa_pri_cal:00888888889999999999999aaaaaaaaabbbbbbbbcedfffffffffffffffffffffffff966666666666666666666666666666666666666666666666666633333333333333333333333333333333300000000000000000000000666eeeeeeeeeeeeeeeeeeeeeefffffffffffffffffffddddddddddddbbbbbbbbbbbbbbbbbcccccccccccccccccccccccccaaaaaaaaaaaaaaaaaaaaaaaaaa88888888644444444444777777777777777799999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999555555555555555555555555555555555555555522222222222222222222222222222222222222
rsa_pub_cal:0c0b82faa9ea15227d77e043db0467261bf4957450ff3342a51f0ebc41112a0a62f509c4d8c6d6554e4d95997f89f6b4ff6ea728287bd6324f9989cdbfe9057740184eca47cb1d07bb082e8e09f4fb9e6befba4765b06fc0ddf4b9ddfa744fde3404ef5106bd772373a41bbc463c63808c972790bed8991089f62ee9f20ab638d177c0abe9b0b706639e782186515418a1bc743513051cd562a8b081b9d25b70eea813a7a48ede372833723fe4bbf7d8b4b20dc1457ae9277f4f4ff4c35873933bdb5eb99fc1bf9b1ec37a3e0ee542eadbdf89340dc90888747b221a35a43107fcdd2eeed2b9962277032b711d3713f7a1ce63318bae02ca462584850a182b32
rsa_pri_cal:0002c30f4202dcace6f9d5e2ff47c9014a4f8c7ca2dcd0fd54ee7d3eead63eb67ca9b76980a7b5d1cd72cab7c56e9aa142b59a79dcf07e5d1189ee09727b5ca372697be5cf6fda20a7cefab1c558c1a6e57609773c0355f407198250d252a4f8d01785f9271e9d160aae2ba2dc2314714fb4cca0b20320b6329224c5ba154b086d479ccd27353d9d9eaa48f5e1743b2fd44e0f46b85d894a41e239c696f1e9a71a22c83c9f69ce1541ebcd1106446c1f5c5b074ec5b580f4263930ffdf9bbdc7bf1cd6d86971744173a15d3eefbe7f1ab8c5363c5d62eccce5c404c3cb954a7f7c09a61dd75e56dcef2fbc98593dbe52f0e317ee5a5f65001122334455667788

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/461517.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Tita:什么是 360 评估?

360 评估是一个专业的反馈机会&#xff0c;使一组同事和经理能够提供有关同事绩效的反馈。与仅由其经理评估员工工作绩效的典型员工绩效评估不同&#xff0c;360 评估会考虑来自同事和报告员工的反馈&#xff0c;甚至包括客户和与员工互动的其他人。 Tita&#xff1a;什么是 3…

jenkins ssh 免密报错Host key verification failed.

jenkins 发布项目&#xff0c;ssh连接远程服务器时报错&#xff1a;Host key verification failed. 解决&#xff1a; 原因是生成的sshkey不是用的jenkins用户&#xff0c;所以切换用户到&#xff1a;jenkins重新生成sshkey su jenkins ssh-keygen -t rsa ssh-copy-id -i ~/…

【Linux第七课--基础IO】内存级文件、重定向、缓冲区、文件系统、动态库静态库

目录 引入内存级文件重新使用C文件接口 -- 对比重定向写文件读文件文件流 认识文件操作的系统接口open参数 -- flagflag的内容宏的传参方式 open关闭文件写文件读文件结论 引入文件描述符fd、对文件的理解理解一切皆文件方法集文件fd的分配规则 重定向代码的重定向输入重定向输…

创意设计的起点:十大网页设计模板网站

对于网页设计领域的专业人士和爱好者而言&#xff0c;从零开始构建一个网页可能会耗费大量的时间和劳力。幸运的是&#xff0c;我们可以通过使用现成的网页模板来提升工作效率并节省宝贵的时间。一个好的模板不仅能提高设计效率&#xff0c;还能激发出卓越的创意灵感。因此&…

鸿蒙Harmony-矩形绘制组件Rect使用详解

目录 一&#xff0c;定义 二&#xff0c;绘制自定义图形 三&#xff0c;作为其他控件背景使用 一&#xff0c;定义 Rect是鸿蒙提供的矩形绘制组件&#xff0c;利用该组件可以绘制矩形背景&#xff0c;矩形图案等 官方提供的参数和属性&#xff1a; 参数&#xff1a; 参数名…

netty之bootstrap源码分析

写在前面 本文看下bootstrap类。 1&#xff1a;正文 1.1&#xff1a;干啥的&#xff1f; 在进行netty编程的时候都是先创建一个bootstrap&#xff0c;然后设置很多的东西&#xff0c;如下代码&#xff08;服务端启动代码&#xff09;&#xff1a; ServerBootstrap b new …

c# WinForm弹出窗体时不获取焦点方法

WinForm开发的软件有时候需要在屏幕右下角弹窗进行一些提示&#xff0c;通常使用new MyForm().Show()即可实现此需求。 但是当MyForm显示出来时&#xff0c;会抢走原本窗体上的光标&#xff0c;导致原本在软件上比如打字或者其他操作被中断&#xff0c;非常不人性化&#xff0…

方差和标准差哪些事儿

1.方差 在概率论与数理统计中&#xff0c;方差用来度量随机变量和其数学期望&#xff08;即均值&#xff09;之间的偏离程度。方差是各个数据与平均数之差的平方和的平均数,即: s(1/n)[(x1-x_)^2 (x2-x_)^2 …(xn-x_)^2] 其中&#xff0c;x_表示样本的平均数&#xff0c;n表示…

Hudi Upsert原理

1. 前言 如果要深入了解Apache Hudi技术的应用或是性能调优&#xff0c;那么明白源码中的原理对我们会有很大的帮助。Upsert是Apache Hudi的核心功能之一&#xff0c;主要完成增量数据在HDFS/对象存储上的修改&#xff0c;并可以支持事务。而在Hive中修改数据需要重新分区或重…

了解SQLExpress数据库

SQLExpress&#xff08;Microsoft SQL Server Express&#xff09;是由微软公司开发的一款免费且轻量级的数据库管理系统。以下是关于SQLExpress的详细解释&#xff1a; 一、定义与特点 定义&#xff1a; SQLExpress是Microsoft SQL Server的一个缩减版或基础版&#xff0c;旨在…

空天地遥感数据识别与计算

在科技飞速发展的时代&#xff0c;遥感数据的精准分析已经成为推动各行业智能决策的关键工具。从无人机监测农田到卫星数据支持气候研究&#xff0c;空天地遥感数据正以前所未有的方式为科研和商业带来深刻变革。然而&#xff0c;对于许多专业人士而言&#xff0c;如何高效地处…

JavaEE-多线程初阶(2)

目录 1.创建线程的五种写法 1.1 继承Thread类 1.2 实现Runnable接口 1.3 使用匿名内部类 1.4 使用Runnable&#xff0c;匿名内部类 1.5 引入lambda表达式 2.Thread类及常见方法 2.1 认识Thread 2.2 Thread的常见构造方法 2.3 Thread的几个常见属性 关于后台线程 关…

【网络安全】揭示 Web 缓存污染与欺骗漏洞

未经许可,不得转载。 文章目录 前言污染与欺骗Web 缓存污染 DoS1、HTTP 头部超大 (HHO)2、HTTP 元字符 (HMC)3、HTTP 方法覆盖攻击 (HMO)4、未键入端口5、重定向 DoS6、未键入头部7、Host 头部大小写规范化8、路径规范化9、无效头部 CP-DoS10、HTTP 请求拆分Web 缓存污染与有害…

重工业数字化转型创新实践:某国家特大型钢铁企业如何快速落地基于实时数仓的数据分析平台

使用 TapData&#xff0c;化繁为简&#xff0c;摆脱手动搭建、维护数据管道的诸多烦扰&#xff0c;轻量替代 OGG, Kettle 等同步工具&#xff0c;以及基于 Kafka 的 ETL 解决方案&#xff0c;「CDC 流处理 数据集成」组合拳&#xff0c;加速仓内数据流转&#xff0c;帮助企业…

Golang | Leetcode Golang题解之第522题最长特殊序列II

题目&#xff1a; 题解&#xff1a; func isSubseq(s, t string) bool {ptS : 0for ptT : range t {if s[ptS] t[ptT] {if ptS; ptS len(s) {return true}}}return false }func findLUSlength(strs []string) int {ans : -1 next:for i, s : range strs {for j, t : range s…

(C#面向初学者的 .NET 的生成 AI) 第 1 部分-简介

第 1 部分简介就是由Luis Quintanilla讲述本系列教程要学习哪些部分&#xff0c;基本都是介绍&#xff0c;内容不是很多。但可以先了解一下.net 生成式AI需要学习接触哪些东西。 在这个关于机器学习和AI的初学者系列中&#xff0c;Luis Quintanilla向.net开发人员介绍了基础知识…

【密码学】全同态加密基于多项式环计算的图解

全同态加密方案提供了一种惊人的能力 —— 能够在不知道数据具体内容的情况下对数据进行计算。这使得你可以在保持潜在敏感源数据私密的同时&#xff0c;得出问题的答案。 这篇文章的整体结构包括多项式环相关的数学介绍&#xff0c;基于多项式环的加密和解密是如何工作的&…

Spring Boot中解决BeanDefinitionStoreException问题的实战分享

目录 前言1. 问题背景2. 问题分析2.1 异常分析2.2 常见的错误原因2.3 排查过程 3. 解决方案3.1 清理缓存和重建项目3.1.1 清理IDEA缓存3.1.2 使用Maven清理并重建项目 3.2 升级Maven版本3.2.1 下载最新Maven版本3.2.2 IDEA配置新的Maven版本3.2.3 清理缓存并重新构建 3.3 验证问…

Java避坑案例 - 线程池未复用引发的故障复盘及源码分析

文章目录 问题现象问题定位问题代码根因分析现象剖析newCachedThreadPool 源码SynchronousQueue特点构造方法主要方法应用场景Code Demo运行结果 问题修复 问题现象 时不时有报警提示线程数过多&#xff0c;超过2000 个&#xff0c;收到报警后查看监控发现&#xff0c;瞬时线程…

AHB Matrix 四星级 验证笔记(1.8-1.9)scoreboard的实现

文章目录 前言一、scoreboard接收数据的方式和比较行为的策略选择1.接受数据的方式1. 首先是数据从哪儿来&#xff1f; 2.比较数据的方式1.方案一2.方案二3. 方案的选择 二、scoreboard的实现1.代码 三、tip1.编辑断点2. return3.有关函数的返回值&#xff1a;函数内部隐式声明…