public class RsaUtil extends Object
1. 公钥负责加密,私钥负责解密; 2. 私钥负责签名,公钥负责验证。
| Modifier and Type | Field and Description |
|---|---|
static String |
RSA_ALGORITHM
数字签名,密钥算法
|
static String |
RSA_PADDING |
| Constructor and Description |
|---|
RsaUtil() |
| Modifier and Type | Method and Description |
|---|---|
static byte[] |
decrypt(PrivateKey privateKey,
byte[] data)
解密
|
static byte[] |
decrypt(String base64PrivateKey,
byte[] data)
解密
|
static byte[] |
decryptByPublicKey(PublicKey publicKey,
byte[] data)
解密
|
static byte[] |
decryptByPublicKey(String base64publicKey,
byte[] data)
解密
|
static byte[] |
decryptByPublicKeyFromBase64(PublicKey publicKey,
byte[] base64Data)
base64 数据解密
|
static String |
decryptByPublicKeyFromBase64(PublicKey publicKey,
String base64Data)
base64 数据解密
|
static byte[] |
decryptByPublicKeyFromBase64(String base64PublicKey,
byte[] base64Data)
base64 数据解密
|
static String |
decryptByPublicKeyFromBase64(String base64PublicKey,
String base64Data)
base64 数据解密
|
static String |
decryptFromBase64(PrivateKey privateKey,
String base64Data)
base64 数据解密
|
static byte[] |
decryptFromBase64(String base64PrivateKey,
byte[] base64Data)
base64 数据解密
|
static String |
decryptFromBase64(String base64PrivateKey,
String base64Data)
base64 数据解密
|
static byte[] |
decryptRsa(Key key,
byte[] data)
解密
|
static byte[] |
encrypt(PublicKey publicKey,
byte[] data)
公钥加密
|
static byte[] |
encrypt(String base64PublicKey,
byte[] data)
公钥加密
|
static byte[] |
encryptByPrivateKey(PrivateKey privateKey,
byte[] data)
私钥加密,用于 qpp 内,公钥解密
|
static byte[] |
encryptByPrivateKey(String base64PrivateKey,
byte[] data)
私钥加密,用于 qpp 内,公钥解密
|
static String |
encryptByPrivateKeyToBase64(String base64PrivateKey,
byte[] data)
私钥加密,加密成 base64 字符串,用于 qpp 内,公钥解密
|
static byte[] |
encryptRsa(Key key,
byte[] data)
公钥加密
|
static String |
encryptToBase64(PublicKey publicKey,
String data)
公钥加密
|
static String |
encryptToBase64(String base64PublicKey,
String data)
公钥加密
|
static PrivateKey |
generatePrivateKey(BigInteger modulus,
BigInteger exponent)
生成RSA私钥
|
static PrivateKey |
generatePrivateKey(String modulus,
String exponent)
生成RSA私钥
|
static PublicKey |
generatePublicKey(BigInteger modulus,
BigInteger exponent)
生成RSA公钥
|
static PublicKey |
generatePublicKey(String modulus,
String exponent)
生成RSA公钥
|
static KeyPair |
genKeyPair()
获取 KeyPair
|
static KeyPair |
genKeyPair(int keySize)
获取 KeyPair
|
static String |
getKeyString(Key key)
得到密钥字符串(经过base64编码)
|
static PrivateKey |
getPrivateKey(String base64PriKey)
得到私钥
|
static String |
getPrivateKeyToBase64(String base64PriKey)
得到私钥 base64
|
static PublicKey |
getPublicKey(String base64PubKey)
得到公钥
|
static String |
getPublicKeyToBase64(String base64PubKey)
得到公钥字符串
|
public static final String RSA_ALGORITHM
public static final String RSA_PADDING
public static KeyPair genKeyPair()
public static KeyPair genKeyPair(int keySize)
keySize - key sizepublic static PrivateKey generatePrivateKey(String modulus, String exponent)
modulus - N特征值exponent - d特征值PrivateKeypublic static PrivateKey generatePrivateKey(BigInteger modulus, BigInteger exponent)
modulus - N特征值exponent - d特征值PrivateKeypublic static PublicKey generatePublicKey(String modulus, String exponent)
modulus - N特征值exponent - e特征值PublicKeypublic static PublicKey generatePublicKey(BigInteger modulus, BigInteger exponent)
modulus - N特征值exponent - e特征值PublicKeypublic static PublicKey getPublicKey(String base64PubKey)
base64PubKey - 密钥字符串(经过base64编码)public static String getPublicKeyToBase64(String base64PubKey)
base64PubKey - 密钥字符串(经过base64编码)public static PrivateKey getPrivateKey(String base64PriKey)
base64PriKey - 密钥字符串(经过base64编码)public static String getKeyString(Key key)
key - keypublic static String getPrivateKeyToBase64(String base64PriKey)
base64PriKey - 密钥字符串(经过base64编码)public static byte[] encrypt(String base64PublicKey, byte[] data)
base64PublicKey - base64 的公钥data - 待加密的内容public static byte[] encrypt(PublicKey publicKey, byte[] data)
publicKey - 公钥data - 待加密的内容public static byte[] encryptByPrivateKey(String base64PrivateKey, byte[] data)
base64PrivateKey - base64 的私钥data - 待加密的内容public static String encryptByPrivateKeyToBase64(String base64PrivateKey, byte[] data)
base64PrivateKey - base64 的私钥data - 待加密的内容public static byte[] encryptByPrivateKey(PrivateKey privateKey, byte[] data)
privateKey - 私钥data - 待加密的内容@Nullable public static String encryptToBase64(PublicKey publicKey, @Nullable String data)
publicKey - PublicKeydata - 待加密的内容@Nullable public static String encryptToBase64(String base64PublicKey, @Nullable String data)
base64PublicKey - base64 公钥data - 待加密的内容public static byte[] decrypt(String base64PrivateKey, byte[] data)
base64PrivateKey - base64 私钥data - 数据public static byte[] decryptByPublicKey(String base64publicKey, byte[] data)
base64publicKey - base64 公钥data - 数据public static byte[] decrypt(PrivateKey privateKey, byte[] data)
privateKey - privateKeydata - 数据public static byte[] decryptByPublicKey(PublicKey publicKey, byte[] data)
publicKey - PublicKeydata - 数据public static byte[] encryptRsa(Key key, byte[] data)
key - Keydata - 待加密的内容public static byte[] decryptRsa(Key key, byte[] data)
key - Keydata - 数据public static byte[] decryptByPublicKeyFromBase64(PublicKey publicKey, byte[] base64Data)
publicKey - PublicKeybase64Data - base64数据public static byte[] decryptByPublicKeyFromBase64(String base64PublicKey, byte[] base64Data)
base64PublicKey - base64 公钥base64Data - base64数据@Nullable public static String decryptFromBase64(PrivateKey privateKey, @Nullable String base64Data)
privateKey - PrivateKeybase64Data - base64数据@Nullable public static String decryptFromBase64(String base64PrivateKey, @Nullable String base64Data)
base64PrivateKey - base64 私钥base64Data - base64数据public static byte[] decryptFromBase64(String base64PrivateKey, byte[] base64Data)
base64PrivateKey - base64 私钥base64Data - base64数据@Nullable public static String decryptByPublicKeyFromBase64(PublicKey publicKey, @Nullable String base64Data)
publicKey - PublicKeybase64Data - base64数据Copyright © 2024. All rights reserved.