Class CipherSmServiceImpl

java.lang.Object
cn.sinozg.applet.common.service.impl.CipherSmServiceImpl
All Implemented Interfaces:
CipherService

@Service @ConditionalOnProperty(prefix="app.sign", name="crypto-type", havingValue="sm") public class CipherSmServiceImpl extends Object implements CipherService
国密实现 系统加密 使用sm3 签名
Since:
2024-12-04 14:27
Author:
xieyubin
  • Field Details

    • log

      private static final org.slf4j.Logger log
  • Constructor Details

    • CipherSmServiceImpl

      public CipherSmServiceImpl()
  • Method Details

    • encoder

      public String encoder(CharSequence plainText)
      Description copied from interface: CipherService
      加密信息 密码
      Specified by:
      encoder in interface CipherService
      Parameters:
      plainText - 密码
      Returns:
      加密后的数据
    • matches

      public boolean matches(CharSequence plainText, String encodedPassword)
      Description copied from interface: CipherService
      密码匹配
      Specified by:
      matches in interface CipherService
      Parameters:
      plainText - 原始密码
      encodedPassword - 加密后的密码
      Returns:
      是否匹配
    • signature

      public boolean signature(boolean sha2, String signature, String... params)
      Description copied from interface: CipherService
      签名判断 参数排序拼接后 签名再与原始的签名比较
      Specified by:
      signature in interface CipherService
      Parameters:
      sha2 - 是否为 sha2
      signature - 签名字符串
      params - 要签名的数据
      Returns:
      是否与签名一致
    • decryptJson

      public byte[] decryptJson(String content, String asymmetricPrivateKey, String symmetricEncrypt) throws Exception

      先用非对称私钥(java)解密前端传过来的 对称加密加密信息,得到前端生成的随机对称加密 key

      再用 对称加密 key解密得到数据

      Specified by:
      decryptJson in interface CipherService
      Parameters:
      content - 内容
      asymmetricPrivateKey - 非对称私钥
      symmetricEncrypt - 对称加密后的数据
      Returns:
      解密后的数据
      Throws:
      Exception - 异常
    • encrypt

      public RequestParameterEncrypt encrypt(String content, String asymmetricPublicKey) throws Exception
      随机生成16位的 对称加密私钥

      用对称加密私钥 加密json得到加密信息

      用前端传过来的 RSA 公钥加密 aes私钥 得到aes私钥加密信息

      Specified by:
      encrypt in interface CipherService
      Parameters:
      content - 加密信息
      asymmetricPublicKey - 前端传过来的非对称加密公钥
      Returns:
      加密信息
      Throws:
      Exception