Interface CipherService

All Known Implementing Classes:
CipherDefaultServiceImpl, CipherSmServiceImpl

public interface CipherService
抽象出密码层 供系统使用,也可以自行实现
用于 用户密码 系统参数加密解密 签名
目前两组实现 对称Symmetric加密-非对称Asymmetric加密
ASE<----->RSA
SM4<----->SM2
Since:
2024-12-04 14:06
Author:
xieyubin
  • Method Details

    • encoder

      String encoder(CharSequence plainText)
      加密信息 密码
      Parameters:
      plainText - 密码
      Returns:
      加密后的数据
    • matches

      boolean matches(CharSequence plainText, String encodedPassword)
      密码匹配
      Parameters:
      plainText - 原始密码
      encodedPassword - 加密后的密码
      Returns:
      是否匹配
    • signature

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

      byte[] decryptJson(String content, String asymmetricPrivateKey, String symmetricEncrypt) throws Exception
      解密前端传过来的加密数据

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

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

      Parameters:
      content - 内容
      asymmetricPrivateKey - 非对称私钥
      symmetricEncrypt - 对称加密后的数据
      Returns:
      解密后的数据
      Throws:
      Exception - 异常
    • encryptJson

      default Object encryptJson(jakarta.servlet.http.HttpServletRequest request, Object data) throws IOException
      加密数据返回到前端
      Parameters:
      request - request
      data - 请求参数
      Returns:
      请求参数或者加密后的数据
      Throws:
      IOException
    • encrypt

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

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

      用前端传过来的 非对称公钥加密 对称加密私钥 得到对称加密私钥加密信息

      Parameters:
      content - 加密信息
      asymmetricPublicKey - 前端传过来的非对称加密公钥
      Returns:
      加密信息
      Throws:
      Exception