nodejs之sm2加密

const sm2 = require('sm-crypto').sm2;
// e={
//     "Trip": [
//         {
//             "Date": "2025-08-05",
//             "Dep": "PEK",
//             "Arrival": "CKG"
//         }
//     ],
//     "Passenger": {
//         "adult": 1,
//         "child": 0,
//         "baby": 0
//     },
//     "notchType": null,
//     "aimPrice": null,
//     "RequestParameterSecurityIdentificationBit": true
// }
 
 
const c = function(e) {
 
    try {
        const publicKey = '04064c2a3bcafba2c1ca4f5fb8ecd876b23d70fc4479b78f3c8066c02a8c17749458bca86361bc563d2501b61e2ac93a676a1305893aafcc6be2ea48ecb048672e';
        const t = encodeURIComponent(JSON.stringify(e));
 
        // SM2 加密(mode=1 表示 C1C3C2 格式)
 
        const encrypted = sm2.doEncrypt(t, publicKey, 1);
        return encrypted;
    } catch (n) {
        console.log(n);
        return "";
    }
};
 
// console.log(c(info));
posted @ 2025-08-21 18:28  我不是萧海哇~~~  阅读(29)  评论(0)    收藏  举报