人民医院前端

secretKey.js 815B

12345678910111213141516171819202122232425
  1. /**
  2. * txt:要加解密的字符串
  3. *
  4. * @return {string}
  5. */
  6. const sm2 = require('sm-crypto').sm2
  7. // 加密
  8. export const encrypt = (txt) => {
  9. const publicKey = '042DBA45E7B03394F603CADAFCDDEC854D3E01A4E9C52CD799B85B1A14BDB970137AE58BA553D79F058604DC1CD4B77DE5408BA3308E767584100C2B663510C819'
  10. const cipherMode = 0 // 1 - C1C3C2,0 - C1C2C3,默认为1
  11. const encryptData = sm2.doEncrypt(txt, publicKey, cipherMode) // 加密结果
  12. return encryptData
  13. }
  14. // 解密
  15. export const decrypt = (txt) => {
  16. const privateKey = 'BF1F907B4E0487F798DC80AFD7BC2A6201E8514233002272EA3BE2FC6F797843'
  17. const cipherMode = 0 // 1 - C1C3C2,0 - C1C2C3,默认为1
  18. if (!txt) {
  19. return
  20. }
  21. txt = txt.substr(2)
  22. const decryptData = sm2.doDecrypt(txt, privateKey, cipherMode) // 解密结果
  23. return decryptData
  24. }