q-koa 13.8.35 → 13.8.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -121,7 +121,10 @@ const validateUnionNotifySign = ({ notifyData, signType, publicKey, md5Key }) =>
121
121
  // 默认 RSA-SHA1(与 allinpay.js verifySign 保持一致)
122
122
  if (!publicKey) return false
123
123
  try {
124
- const pem = `-----BEGIN PUBLIC KEY-----\n${publicKey}\n-----END PUBLIC KEY-----`
124
+ // 兼容两种配置格式:已经带 PEM 头尾的直接用;纯 base64 body 再包裹头尾
125
+ const pem = String(publicKey).includes('-----BEGIN')
126
+ ? String(publicKey)
127
+ : `-----BEGIN PUBLIC KEY-----\n${publicKey}\n-----END PUBLIC KEY-----`
125
128
  const verify = crypto.createVerify('RSA-SHA1')
126
129
  verify.update(signStr, 'utf8')
127
130
  return verify.verify(pem, sign, 'base64')
@@ -67,10 +67,16 @@ class AllinPay {
67
67
  const signStr = this.buildSignStr(params)
68
68
 
69
69
  if (this.signType === 'RSA') {
70
- const privateKey = `-----BEGIN RSA PRIVATE KEY-----\n${this.privateKey}\n-----END RSA PRIVATE KEY-----`
70
+ // 兼容三种配置格式:已经带 PEM 头尾直接使用;否则默认包 PKCS#1 (BEGIN RSA PRIVATE KEY) 头尾
71
+ let pem
72
+ if (String(this.privateKey).includes('-----BEGIN')) {
73
+ pem = String(this.privateKey)
74
+ } else {
75
+ pem = `-----BEGIN RSA PRIVATE KEY-----\n${this.privateKey}\n-----END RSA PRIVATE KEY-----`
76
+ }
71
77
  const sign = crypto.createSign('RSA-SHA1')
72
78
  sign.update(signStr, 'utf8')
73
- const signature = sign.sign(privateKey, 'base64')
79
+ const signature = sign.sign(pem, 'base64')
74
80
 
75
81
  // crypto.createHash('md5').update(originStr).digest('hex')
76
82
  return signature
@@ -93,10 +99,13 @@ class AllinPay {
93
99
 
94
100
  const signStr = this.buildSignStr(paramsCopy)
95
101
 
96
- const publicKey = `-----BEGIN PUBLIC KEY-----\n${this.publicKey}\n-----END PUBLIC KEY-----`
102
+ // 兼容两种配置格式:已经带 PEM 头尾的直接用;纯 base64 body 再包裹头尾
103
+ const pem = String(this.publicKey).includes('-----BEGIN')
104
+ ? String(this.publicKey)
105
+ : `-----BEGIN PUBLIC KEY-----\n${this.publicKey}\n-----END PUBLIC KEY-----`
97
106
  const verify = crypto.createVerify('RSA-SHA1')
98
107
  verify.update(signStr, 'utf8')
99
- const result = verify.verify(publicKey, sign, 'base64')
108
+ const result = verify.verify(pem, sign, 'base64')
100
109
 
101
110
  return result
102
111
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q-koa",
3
- "version": "13.8.35",
3
+ "version": "13.8.36",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {