类 RSAUtil

java.lang.Object
com.walker.infrastructure.utils.RSAUtil

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

    • UTF8

      public static final Charset UTF8
    • DEFAULT_ALGORITHM

      public static final String DEFAULT_ALGORITHM
      另请参阅:
    • KEY_ALGORITHM

      public static final String KEY_ALGORITHM
      加密算法RSA
      另请参阅:
    • SIGNATURE_ALGORITHM

      public static final String SIGNATURE_ALGORITHM
      签名算法
      另请参阅:
    • SIGNaTURE_ALGORITHM_SHA1_RSA

      public static final String SIGNaTURE_ALGORITHM_SHA1_RSA
      另请参阅:
    • privateKeyPath

      public static String privateKeyPath
    • publicKeyPath

      public static String publicKeyPath
  • 构造器详细资料

    • RSAUtil

      public RSAUtil()
  • 方法详细资料

    • generateKey

      public static KeyPair generateKey() throws NoSuchAlgorithmException
      生成秘钥对
      返回:
      抛出:
      NoSuchAlgorithmException
    • toHexString

      public static String toHexString(byte[] b)
    • toBytes

      public static final byte[] toBytes(String s)
    • genKeyPair

      public static Map<String,Object> genKeyPair() throws Exception

      生成密钥对(公钥和私钥)

      返回:
      抛出:
      Exception
    • sign

      public static String sign(byte[] data, String privateKey) throws Exception

      用私钥对信息生成数字签名

      参数:
      data - 已加密数据
      privateKey - 私钥(BASE64编码)
      返回:
      抛出:
      Exception
    • signWithSha1Rsa

      public static String signWithSha1Rsa(String content, String privateKey)
      签名算法,使用SHA1WithRSA,目前支付宝使用。
      参数:
      content -
      privateKey -
      返回:
    • verifyWithSha1Rsa

      public static boolean verifyWithSha1Rsa(String content, String sign, String alipay_public_key, String input_charset) throws Exception
      验证签名,目前支付宝使用
      参数:
      content -
      sign -
      alipay_public_key -
      input_charset -
      返回:
      抛出:
      Exception
    • verify

      public static boolean verify(byte[] data, String publicKey, String sign) throws Exception

      校验数字签名

      参数:
      data - 已加密数据
      publicKey - 公钥(BASE64编码)
      sign - 数字签名
      返回:
      抛出:
      Exception
    • decryptByPrivateKey

      public static byte[] decryptByPrivateKey(byte[] encryptedData, String privateKey) throws Exception

      私钥解密

      参数:
      encryptedData - 已加密数据
      privateKey - 私钥(BASE64编码)
      返回:
      抛出:
      Exception
    • decryptByPublicKey

      public static byte[] decryptByPublicKey(byte[] encryptedData, String publicKey) throws Exception

      公钥解密

      参数:
      encryptedData - 已加密数据
      publicKey - 公钥(BASE64编码)
      返回:
      抛出:
      Exception
    • encryptByPublicKey

      public static byte[] encryptByPublicKey(byte[] data, String publicKey) throws Exception

      公钥加密

      参数:
      data - 源数据
      publicKey - 公钥(BASE64编码)
      返回:
      抛出:
      Exception
    • encryptByPrivateKey

      public static byte[] encryptByPrivateKey(byte[] data, String privateKey) throws Exception

      私钥加密

      参数:
      data - 源数据
      privateKey - 私钥(BASE64编码)
      返回:
      抛出:
      Exception
    • getPrivateKey

      public static String getPrivateKey(Map<String,Object> keyMap) throws Exception

      获取私钥

      参数:
      keyMap - 密钥对
      返回:
      抛出:
      Exception
    • getPublicKey

      public static String getPublicKey(Map<String,Object> keyMap) throws Exception

      获取公钥

      参数:
      keyMap - 密钥对
      返回:
      抛出:
      Exception
    • getPublicKey

      public static PublicKey getPublicKey(String key) throws Exception
      抛出:
      Exception
    • encrypt

      public static byte[] encrypt(PublicKey pubkey, String text)
    • decrypt

      public static String decrypt(PrivateKey decryptionKey, byte[] buffer)