How to use digital signature in jsrsasign.js with Chinese Character?

Viewed 195

I need to interface with third-party organizations. They need to add a digital signature to the data and put it in the request header.

I found that jsrsasign.js could be helpful so I am using that to do the digital signature, but always with the wrong result.

enter image description here

my code:

import { RSAKey, KEYUTIL, KJUR, hex2b64 } from 'jsrsasign'
export function signature (url) {
  // 创建RSAKey对象
  var rsa = new RSAKey()
  let k = '-----BEGIN PRIVATE KEY-----x-----END PRIVATE KEY-----'
  // 将密钥转码
  rsa = KEYUTIL.getKey(k)
  // 创建Signature对象,设置签名编码算法
  var sig = new KJUR.crypto.Signature({'alg': 'SHA256withRSA'})
  // 初始化
  sig.init(rsa)
  console.log('***url***', url)
  // 传入待加密字符串
  sig.updateString(url)
  // 生成密文
  var sign = hex2b64(sig.sign())
  console.log('**sign**', sign)
  return sign
}
1 Answers

I'm a jsrsasign maintainer. It shall be work if your code or page is in UTF-8 even though Chinese, Cyrillic or Japanese characters.

Related