小程序
小游戏
企业微信
微信支付
扫描小程序码分享
求个用nodejs实现SHA256 with RSA签名的代码。
谢谢大佬先了。
3 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
class Rsa { /** * Encrypts text with sha256WithRSAEncryption/RSA_PKCS1_OAEP_PADDING. * Recommended Node Limits Version >= 12.9.0 (`oaepHash` was available), even it works on v10.15.0. * * @param {string} plaintext - Cleartext to encode. * @param {string|Buffer} publicCertificate - A PEM encoded public certificate. * * @returns {string} Base64-encoded ciphertext. */ static encrypt(plaintext, publicCertificate) { return crypto.publicEncrypt({ oaepHash: sha1, key: publicCertificate, padding: RSA_PKCS1_OAEP_PADDING, }, Buffer.from(plaintext, utf8)).toString(base64) } }
源码可见 https://github.com/TheNorthMemory/wechatpay-axios-plugin/blob/master/lib/rsa.js
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
const nonceStr = Math.random().toString(36).slice(-10) const timestamp = (new Date().getTime() / 1000).toFixed(0) const message = `GET\n/v3/certificates\n${timestamp}\n${nonceStr}\n\n` const signature = crypto.createSign('RSA-SHA256').update(message, 'utf-8').sign(fs.readFileSync('apiclient_key.pem').toString(), 'base64')
网上有找到点相关的加密函数,但是参数密码相关的参数意思完全不懂。。
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
class Rsa { /** * Encrypts text with sha256WithRSAEncryption/RSA_PKCS1_OAEP_PADDING. * Recommended Node Limits Version >= 12.9.0 (`oaepHash` was available), even it works on v10.15.0. * * @param {string} plaintext - Cleartext to encode. * @param {string|Buffer} publicCertificate - A PEM encoded public certificate. * * @returns {string} Base64-encoded ciphertext. */ static encrypt(plaintext, publicCertificate) { return crypto.publicEncrypt({ oaepHash: sha1, key: publicCertificate, padding: RSA_PKCS1_OAEP_PADDING, }, Buffer.from(plaintext, utf8)).toString(base64) } }
源码可见 https://github.com/TheNorthMemory/wechatpay-axios-plugin/blob/master/lib/rsa.js
const nonceStr = Math.random().toString(36).slice(-10) const timestamp = (new Date().getTime() / 1000).toFixed(0) const message = `GET\n/v3/certificates\n${timestamp}\n${nonceStr}\n\n` const signature = crypto.createSign('RSA-SHA256').update(message, 'utf-8').sign(fs.readFileSync('apiclient_key.pem').toString(), 'base64')
网上有找到点相关的加密函数,但是参数密码相关的参数意思完全不懂。。