类 RsaUtils

java.lang.Object
cn.zhxu.toys.util.RsaUtils

public class RsaUtils extends Object
  • 字段详细资料

  • 构造器详细资料

    • RsaUtils

      public RsaUtils()
  • 方法详细资料

    • generateKey

      public static RsaUtils.RsaKey generateKey()
    • generateKey

      public static RsaUtils.RsaKey generateKey(int keySize)
      初始化密钥对
      返回:
      Map 甲方密钥的Map
    • encryptByPrivateKey

      public static byte[] encryptByPrivateKey(byte[] data, byte[] key) throws Exception
      私钥加密
      参数:
      data - 待加密数据
      key - 密钥
      返回:
      byte[] 加密数据
      抛出:
      Exception
    • encryptByPrivateKey

      public static byte[] encryptByPrivateKey(byte[] data, PrivateKey privateKey) throws Exception
      私钥加密
      参数:
      data - 待加密数据
      privateKey - 密钥
      返回:
      byte[] 加密数据
      抛出:
      Exception
    • encryptByPublicKey

      public static byte[] encryptByPublicKey(byte[] data, byte[] key) throws Exception
      公钥加密
      参数:
      data - 待加密数据
      key - 公钥
      返回:
      byte[] 加密数据
      抛出:
      Exception
    • encryptByPublicKey

      public static byte[] encryptByPublicKey(byte[] data, byte[] key, String algorithm) throws Exception
      公钥加密
      参数:
      data - 待加密数据
      key - 公钥
      algorithm - 规则 支持如下 RSA/ECB/RSA_NO_PADDING RSA/ECB/RSA_PKCS1_PADDING RSA/ECB/RSA_PKCS1_OAEP_PADDING RSA/ECB/OAEPWithSHA-1AndMGF1Padding
      返回:
      byte[] 加密数据
      抛出:
      Exception
    • encryptByPublicKey

      public static byte[] encryptByPublicKey(byte[] data, PublicKey publicKey, String algorithm) throws Exception
      公钥加密
      参数:
      data - 待加密数据
      publicKey - 公钥
      返回:
      byte[] 加密数据
      抛出:
      Exception
    • decryptByPrivateKey

      public static byte[] decryptByPrivateKey(byte[] data, byte[] key) throws Exception
      私钥解密
      参数:
      data - 待解密数据
      key - 密钥
      返回:
      byte[] 解密数据
      抛出:
      Exception
    • decryptByPrivateKey

      public static byte[] decryptByPrivateKey(byte[] data, PrivateKey privateKey) throws Exception
      私钥解密
      参数:
      data - 待解密数据
      privateKey - 私钥
      返回:
      byte[] 解密数据
      抛出:
      Exception
    • decryptByPublicKey

      public static byte[] decryptByPublicKey(byte[] data, byte[] key) throws Exception
      公钥解密
      参数:
      data - 待解密数据
      key - 公钥
      返回:
      byte[] 解密数据
      抛出:
      Exception
    • decryptByPublicKey

      public static byte[] decryptByPublicKey(byte[] data, PublicKey publicKey) throws Exception
      公钥解密
      参数:
      data - 待解密数据
      publicKey - 公钥
      返回:
      byte[] 解密数据
      抛出:
      Exception