当前位置: 首页 > news >正文

网站设计要如何做支付功能惠州网站设计定制

网站设计要如何做支付功能,惠州网站设计定制,做网站找哪家最好,做冲压件加工有什么好网站前端使用 jsencrypt 进行加密#xff0c;服务端使用 node-rsa 或 crypto 进行解密。 jsencrypt 加密 需要注意的是 RSA 加密的数据长度是有限制的#xff0c;过长的数据可能导致解密失败。允许的数据长度与密钥长度成正比。 import JSEncrypt from jsencrypt;// 通过 node…前端使用 jsencrypt 进行加密服务端使用 node-rsa 或 crypto 进行解密。 jsencrypt 加密 需要注意的是 RSA 加密的数据长度是有限制的过长的数据可能导致解密失败。允许的数据长度与密钥长度成正比。 import JSEncrypt from jsencrypt;// 通过 node-rsa 或 crypto 生成的公钥也可以其他方式生成只要与私钥成对即可 const PUBLIC_KEY -----BEGIN PUBLIC KEY----- MIIBIjA ...... owIDAQAB -----END PUBLIC KEY----- ;/*** 对数据进行 RSA 加密加密失败时会返回 false。** JSEncrypt 只能加密字符串数据因此使用 JSON.stringify 对要加密的数据进行序列化** 但此时需要注意一些 JSON.stringify 的问题** 比如JSON.stringify(undefined) undefined // 这不是一个字符串* 比如JSON.stringify({ prop: undefined }) {}* 比如JSON.stringify(NaN) null** param {string | number | Object | Array} data 需要加密的数据* param {string} publicKey 公钥可选* returns {string | false} 密文*/ export const EncryptByRSA (data, publicKey PUBLIC_KEY) {const encrypt new JSEncrypt();encrypt.setPublicKey(publicKey);return encrypt.encrypt(JSON.stringify(data)); };/*** 对密文进行 RSA 解密秘钥不对会返回 false数据不是加密后的密文会返回 null。** 会使用 JSON.parse 对解密后数据进行反序列化** param {string} secretText 待解密的字符串* param {string} privateKey 私钥* returns {any} 解密后的数据*/ export const DecryptByAES (secretText, privateKey) {const decrypt new JSEncrypt();decrypt.setPrivateKey(privateKey);return JSON.parse(decrypt.decrypt(secretText)); };crypto 解密 需要注意的是解密时需要设置正确的 padding否则可能无法对 jsencrypt 加密的数据进行解密。 import crypto from crypto;/*** 生成 RSA 公私钥对* return {Object} { publicKey, privateKey }*/ export const generateRSAKeyPair () {const { publicKey, privateKey } crypto.generateKeyPairSync(rsa, {modulusLength: 2048, // 秘钥长度// 秘钥配置详见 https://nodejs.cn/dist/latest-v18.x/docs/api/crypto.html#keyobjectexportoptionspublicKeyEncoding: {type: spki, // 编码类型format: pem // 编码格式},privateKeyEncoding: {type: pkcs8,format: pem}});return { publicKey, privateKey }; };/*** 使用公钥进行加密加密出错会抛出异常* param {any} data 需要加密的数据会使用 JSON.stringify 序列化* param {string} publicKey* return {string} 加密后的密文*/ export const encrypt (data, publicKey) {const dataJSON JSON.stringify(data);return crypto.publicEncrypt(publicKey, Buffer.from(dataJSON, utf-8)).toString(base64); };/*** 使用私钥进行解密解密出错会抛出异常* param {string} secretText 密文* param {string} privateKey 私钥* return {String} 解密后的明文会使用 JSON.parse 反序列化*/ export const decrypt (secretText, privateKey) {const dataStr crypto.privateDecrypt({key: privateKey,// padding 的值需要与公钥的编码类型相对应padding: crypto.constants.RSA_PKCS1_PADDING},Buffer.from(secretText, base64)).toString(utf-8);return JSON.parse(dataStr); };node-rsa 解密 import NodeRSA from node-rsa;/*** 生成 RSA 公私钥对* return {Object} { publicKey, privateKey }*/ export const generateRSAKeyPair () {const key new NodeRSA({ b: 512 }); // 指定密钥长度key.setOptions({ encryptionScheme: pkcs1 }); // 指定加密格式const publicKey key.exportKey(pkcs8-public-pem); //制定输出格式const privateKey key.exportKey(pkcs8-private-pem);return { publicKey, privateKey }; };/*** 使用公钥进行加密加密出错会抛出异常* param {any} data 需要加密的数据会使用 JSON.stringify 序列化* param {string} publicKey* return {string} 加密后的密文*/ export const encrypt (data, publicKey) {const encrypt new NodeRSA(publicKey, pkcs8-public-pem);encrypt.setOptions({ encryptionScheme: pkcs1 });return encrypt.encrypt(JSON.stringify(data), base64); };/*** 对密文进行 RSA 解密。如果解密失败则抛出异常* param {string} secretText 密文* param {string} privateKey 私钥* return {String} 解密后的明文会使用 JSON.parse 反序列化*/ export const decrypt (secretText, privateKey) {const decrypt new NodeRSA(privateKey, pkcs8-private-pem);// jsencrypt 自身使用的是 pkcs1 加密方案所以这里设置为 pkcs1decrypt.setOptions({ encryptionScheme: pkcs1 });return JSON.parse(decrypt.decrypt(secretText, utf8)); };
http://wiki.neutronadmin.com/news/33117/

相关文章:

  • 织梦网站栏目无法生成怎么在手机上做微电影网站
  • 网站黑链检测端午节网站怎么做
  • 网站设计的关键做的比较好看的国内网站
  • 站长统计免费下载网络推广公司重诚
  • 邢台大峡谷烟台seo网站诊断
  • 陕西网站建设价格佛山顺德容桂网站制作
  • 对网站开发的理解500字wordpress 简洁主题
  • 查看网站域名网站搜索引擎提交
  • 网站平台如何推广济南中建设计院 官方网站
  • 潍坊市建设工程质量安全监督站网站wordpress主题的文件在哪个文件夹
  • 平乡县网站建设国内服装电商平台
  • 大型网站制作平台苏州保洁公司哪家最好
  • 进口食品销售销售在那个网站做个人网站建设的目的
  • 网站建设行业网站wordpress类别id
  • 扁平化色块风格的网站固定ip如何做网站服务器
  • 连云港网站关键字优化如何东莞市网站seo
  • 高端的网站设计公司廉洁长沙网站
  • 做装饬在哪家网站挂wordpress推荐适合seo的主题
  • 团支书登录智慧团建网站哪里有学做ppt的网站
  • 屏幕分辨率 网站开发江苏中兴建设有限公司网站
  • 基于asp.net电子商务网站开发实践中的关键技术和应用flash代码做网站教程
  • c 精品课程建设网站源程序asp加dw做网站
  • 做低价的跨境电商网站广州市照明建设管理中心网站
  • 上市设计网站对电子商务网站建设的认识
  • 旅游网站建设风险建设银行网站用什么字体
  • 苍梧网站建设公司产品营销广告宣传
  • 电子产品网站建设分析的摘要西安网络科技公司
  • 做企业网站有什么好处网站建设需求分析运行环境处理器型号及内存容量
  • 网站免费永久广东深圳龙华区
  • 内网穿透做网站河池网站优化