sm2.js 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. /*
  2. * @Description: file content
  3. * @Version: 2.0
  4. * @Author: ljl
  5. * @Date: 2022-07-07 13:34:28
  6. * @LastEditors: ljl
  7. * @LastEditTime: 2022-07-07 14:33:12
  8. * @FilePath: \sui-shen-ban_alipay\src\utils\sm2.js
  9. */
  10. const sm2 = require('sm-crypto').sm2
  11. const cipherMode = 0 // 1 - C1C3C2,0 - C1C2C3,默认为1
  12. var publicKeyServer =
  13. "049FFE1205FDDDC59C52320F3DFE49805B2236865E74E96412C152E19591B7831D41FBDC094190F608B805BDE9E90EEFE5755327B8CA9D0EE961B1540F85A723F8";
  14. var privateKeyWeb = "008AD3D59BC6F6D8742EB27894A23FEF91296433BF9FCFF178713E37F60C526838";
  15. export default {
  16. encrypt(params) {
  17. if (typeof (params) == 'undefined') {
  18. params = null;
  19. } else {
  20. let encryptData = sm2.doEncrypt(params, publicKeyServer, cipherMode);
  21. return encryptData;
  22. }
  23. },
  24. decrypt(params) {
  25. if (typeof (params) == 'undefined') {
  26. params = null;
  27. } else {
  28. let decryptData = sm2.doDecrypt(params, privateKeyWeb, cipherMode);
  29. return decryptData;
  30. }
  31. }
  32. }