smCrypto.js 655 B

123456789101112131415161718192021222324252627
  1. /**
  2. * 加解密的工具类
  3. * 使用:https://github.com/JuneAndGreen/sm-crypto
  4. *
  5. * @author yubaoshan
  6. */
  7. import smCrypto from 'sm-crypto'
  8. const sm2 = smCrypto.sm2
  9. const cipherMode = 1 // 1 - C1C3C2,0 - C1C2C3,默认为1
  10. const publicKey =
  11. '04298364ec840088475eae92a591e01284d1abefcda348b47eb324bb521bb03b0b2a5bc393f6b71dabb8f15c99a0050818b56b23f31743b93df9cf8948f15ddb54'
  12. /**
  13. * 国密加解密工具类
  14. */
  15. export default {
  16. // SM2加密
  17. doSm2Encrypt(msgString) {
  18. return sm2.doEncrypt(msgString, publicKey, cipherMode)
  19. },
  20. // SM2数组加密
  21. doSm2ArrayEncrypt(msgString) {
  22. return sm2.doEncrypt(msgString, publicKey, cipherMode)
  23. }
  24. }