-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patha.js
74 lines (59 loc) · 6.36 KB
/
a.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
const crypto = require("crypto");
// 读取加密后的文件
let key1 =
"YKKm6l/wBSs6M08BIhYvyPZd+uNPRHAacwyAGigS3Ea1M2HORKjTPnO0KjT3tdwfbcak3DnG43EgXrz+iKvHzfbCGIzbtf6SRrhFFxJiVBUQ8oyc6bjIHbehx08i6DMuQjuyG5dSLSBe5SkevsUjVVUhotv+Om/Ps7eQDSqYGiATDpSZq0jtAZGDUHCTChRpMku3Jsmwj+lqg9XsQcFiYjVsKwwgO9sXwwJXOdSbTEl3lZV8dfpf9UXup9FBjNO8DcKOc4VZrfdoA5qZWj5tCLyNttcHeRSmc7lyqtAODf6ImAvDw38Bp9S5rPScLyTwKRfZVw2+elDlij78HWcbqZMhRFe844T0HvTumf0LUVMZcjxpKpRrITMJdEE9OzZaccAJw0EiACqaTS7gigB3QMUPf0JAiUttdkKW6zpCiAwE55HUb+F9MqaRULRG14KChyq+onwySbV4yGsc/Kt1yGRUtYrpATLEtqvpXWpBxP8MXG45yboyEbijx3vNYzY16WkimLmb1IYrEmBQyzFUdGOi8s1X/y8yFEJJfg1qj1dVh5L743zK1HphLqY6s9jZzW1pU5Bw0D7pl61Hwmu/TqWYp03aI7PxPFLbT049IZpqwmkYnK/taefQR6vyBot1HSU4wXljJ0h0TYTE/TM4/7N0AOvQjNKL/33L4sBr0I4b8C39N3u9b7psUCC9JhI6ZQHmN6RFe4xcHakHkvpkRW6KsM3wrQR8Kg97XD/b0EQkVjHtDUZhLf4YShWIdgtJZMQPB3Klq6ttnHQN3XCozqDQMgrqX7jweVrKJUZNPzlwC8/UUJevpoCC7wHksnPDHaCT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03Hrc7XApgrxxFVw44rUn4QFbc/p+h+ZvZYMzsjCfYGX4vDDQEHB92v6gsidJkizh7zA/lVfGsve+HREP8LKTZasxGpIqkgXhDWi7vK3lk0QazFu8wk9cWP5WU2VFmYakufdjTZrHv2I9El4v4dLbfX9+9I5IDkCgYBJh1HG0AMRa641bXpxl5FvF6i16o6EJA19pTjGmhh6v9Zrr2g+FkC+GbRyPoMK5XZYwceqd9QvtDKkWAnzvHOYvOm32ZET8I8yU3jBvwLDsX/q6VTxR4BeWyOgE7aj4aWHEin+kUkNwCqSOw6203DXVrtq7V62+Gz+pBQeYx4pvQKBgQCm1ueIzd2a8CFnJSlA6k3+ULGh13n0lefALI39QnR1PO2JPnlMHiVhhfRtiPhP0dcx5gAzcNsqUB1PH+aew2xSE/ZcoHvSMEoEFLLMMI37anciJumsO9uMmicKN7RtluhhRe+FZT0BcelsPi055ZqL4f8K8znVYo4R4+CDFHG0aQKBgQCmNoPUBq85EcnWHuzhnW2GKiFwmsuUkSEEDu7cyR6rRbujEUUjmrhPIUUlJSCUanXODjsto/Zq1D0rdAqpA4snOd+PVi/EeIxgYPqTni250f9XnHBOywbHUI0VWufECXjNFagwiEZYDObXvuLNyrzHcs6dWVe4TbwsFXvlLrpehQ==\n-----END RSA PRIVATE KEY-----";
privateKey = privateKey.replace(
/\s*(-+([^-]+)-+)\s*/g,
(_, comment) => `\n${comment}\n`
);
let MAX_DECRYPT_BLOCK = 256;
let result1 =
"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJ1cG4iOiJ0ZXN0dXNlciIsImlzcyI6ImF1dGguYW8uc3BhY2UiLCJpYXQiOjE3MDcyODUxODcsImV4cCI6MzQxNDY1Njc3NCwiaW5mbyI6InhUVWdjRHRsY08zSTZSVFNid0pNS0hsMCtCQUt1dWpaTUh4aExIWU14ZmRmL3p6b3YrbnJVbXhyOUlpQkphWEFuNDdmYjZBRjhJNjJVSHh0L0VxR2NOeVByMzFHZll6ZGtwOHpnZW9Sajg1Sng0b2s0dGI0M1d2dTFhWjNGZnp5ZGY0bGV0Y09zdU1vdFhSV3VyNm5iRWNRVjAxSkNWTkc4OTNTNWcwb29Ha2o5YUxtc2tTYk4wK09mY0dTL1owYW1iRWUzclZiSTVHTmEyZUMwMy9UajB3Sm95Y3NyMTFPNXpIQ3J1eE0rUk9PSUdZd09EZ3pPa3NKMXdiRjJYNjd3SGdXWFNoRnJxYWpiNTJ4NWtHb1RsRHNuRU5CbElNazAxTHViVWFocXV4S2ZWOC9lN3RIVzFkNlphZ3g5WUp5dHN6TnMwYzVjWXMrNW9scVcwSWp5dz09Iiwic2hhcmVkSW5pdGlhbGl6YXRpb25WZWN0b3IiOiJoVTdCdFhZSkJ0SFV2b0h6TzBXRXBnPT0iLCJ0b2tlblR5cGUiOiJhY2Nlc3MiLCJqdGkiOiI1MDVlNjAyOS04MzdiLTQ0MmMtODI1ZS0yNGRjZGIzOTM1NzMifQ.vRSM-D4yY5DAoQeoKcGy9gea4nJ3mnIh7uoyIdyL5OeTNyQl4KL-EWKth-tJgUD1MsC0Wpbi1MarhbJJ33CAgMEAAnqVP0mQMjsHkLU4lEC5K0gJu8HHKhYdVvIbvy2_HYs1Ar3rO-T5F_jmdSB0HsySa3L1RwFv46HnbOKv9Efs_7NB6pQbJ1WaD318aKQ8T8WvBr2mctfdLY6XGXEAanrP1reJnj6bt3fay8m6ImoEjKUyXfc41Z9iAJ9kBLPIwFEl593Ur24XR1fvvotgDQovLjQf9q4as0crhtGRal1eUCci-XXEJVM8jVeBEJCsxneqIhYj6oIiu95xkDzZ5w==";
let result2 = "231390b0-300f-4be5-8e8e-d70dc03064e4";
let result22 = crypto.privateDecrypt(
{
key: privateKey,
// 在这里,你可以指定padding(如果你在加密时使用了非默认的padding)
padding: crypto.constants.RSA_PKCS1_PADDING,
},
Buffer.from(key2, "base64")
);
let x = result22.toString("utf8");
// 使用私钥分块解密
const decryptedData = decryptWithPrivateKey(
Buffer.from(key1, "base64"),
privateKey
);
// 将Buffer转换为字符串(假设原始数据是字符串)
const y = decryptedData.toString("utf8");
console.log(y === result1);
console.log(x === result2);
// 分块解密函数
function decryptWithPrivateKey(encryptedBuffer, privateKey) {
let decryptedBuffer = Buffer.alloc(0); // 初始化一个空Buffer用于拼接解密后的数据
const totalLength = encryptedBuffer.length;
let offset = 0;
while (offset < totalLength) {
// 截取一块数据进行解密
const block = encryptedBuffer.slice(
offset,
Math.min(offset + MAX_DECRYPT_BLOCK, totalLength)
);
const decryptedChunk = crypto.privateDecrypt(
{
key: privateKey,
padding: crypto.constants.RSA_PKCS1_PADDING,
},
block
);
// 拼接解密后的数据
decryptedBuffer = Buffer.concat([decryptedBuffer, decryptedChunk]);
// 更新偏移量
offset += MAX_DECRYPT_BLOCK;
}
return decryptedBuffer;
}