public class RSATools extends Object
Modifier and Type | Field and Description |
---|---|
static String |
CIPHER_ALGORITHM
貌似默认是RSA/NONE/PKCS1Padding,未验证
|
static String |
KEY_ALGORITHM
加密解密方式
|
static int |
KEY_SIZE
RSA密钥长度必须是64的倍数,在512~65536之间。默认是1024
|
protected static org.slf4j.Logger |
logger |
static String |
PRIVATE_KEY
私钥键名称
|
static String |
PUBLIC_KEY
公钥键名称
|
Constructor and Description |
---|
RSATools() |
Modifier and Type | Method and Description |
---|---|
static byte[] |
decodeBASE64(String str)
base64解码
top.hmtools.security.BASE64.decode(String) |
static String |
encodeBASE64(byte[] bstr)
base64编码
top.hmtools.security.BASE64.encode(byte[]) |
static Map<String,String> |
getGenerateKeyBase64Str(Integer keySize)
获取RSA公钥私钥对(base64编码后)
|
static Map<String,byte[]> |
getGenerateKeyBytes(Integer keySize)
获取RSA公钥私钥对
|
static PrivateKey |
restorePrivateKey(byte[] keyBytes)
还原私钥,PKCS8EncodedKeySpec 用于构建私钥的规范
|
static PrivateKey |
restorePrivateKey(String keyBase64Str)
还原私钥,PKCS8EncodedKeySpec 用于构建私钥的规范
方法说明: restorePrivateKey
输入参数说明: @param keyBase64Str base64编码的私钥字符串
输入参数说明: @return
输出参数说明: PrivateKey
|
static PublicKey |
restorePublicKey(byte[] keyBytes)
还原公钥,X509EncodedKeySpec 用于构建公钥的规范
|
static PublicKey |
restorePublicKey(String keyBase64Str)
还原公钥,X509EncodedKeySpec 用于构建公钥的规范
方法说明: restorePublicKey
输入参数说明: @param keyBase64Str base64编码后的公钥字符串
输入参数说明: @return
输出参数说明: PublicKey
|
static byte[] |
RSADecode(byte[] privateKeyByte,
byte[] encodedText)
解密
|
static byte[] |
RSADecode(PrivateKey key,
byte[] encodedText)
解密
|
static byte[] |
RSADecode(String privateKeyStr,
byte[] encodedText)
解密
方法说明: RSADecode
输入参数说明: @param privateKeyStr base64 编码后的字符串(RSA私钥)
输入参数说明: @param encodedText
输入参数说明: @return
输出参数说明: byte[]
|
static byte[] |
RSAEncode(byte[] publicKeyByte,
byte[] plainText)
加密
方法说明: RSAEncode
输入参数说明: @param publicKeyByte
输入参数说明: @param plainText
输入参数说明: @return
输出参数说明: byte[]
|
static byte[] |
RSAEncode(PublicKey key,
byte[] plainText)
加密
|
static byte[] |
RSAEncode(String publicKeyStr,
byte[] plainText)
加密
|
protected static org.slf4j.Logger logger
public static final String KEY_ALGORITHM
public static final String CIPHER_ALGORITHM
public static final String PUBLIC_KEY
public static final String PRIVATE_KEY
public static final int KEY_SIZE
public static byte[] RSADecode(String privateKeyStr, byte[] encodedText)
public static byte[] RSADecode(byte[] privateKeyByte, byte[] encodedText)
privateKeyByte
- encodedText
- public static byte[] RSADecode(PrivateKey key, byte[] encodedText)
key
- encodedText
- public static byte[] RSAEncode(String publicKeyStr, byte[] plainText)
publicKeyStr
- base64 编码后的字符串(RSA公钥)plainText
- public static byte[] RSAEncode(byte[] publicKeyByte, byte[] plainText)
public static byte[] RSAEncode(PublicKey key, byte[] plainText)
key
- plainText
- public static PrivateKey restorePrivateKey(String keyBase64Str)
public static PrivateKey restorePrivateKey(byte[] keyBytes)
keyBytes
- public static PublicKey restorePublicKey(String keyBase64Str)
public static PublicKey restorePublicKey(byte[] keyBytes)
keyBytes
- public static Map<String,String> getGenerateKeyBase64Str(Integer keySize)
keySize
- RSA密钥长度必须是64的倍数,在512~65536之间。默认是 2048public static Map<String,byte[]> getGenerateKeyBytes(Integer keySize)
keySize
- RSA密钥长度必须是64的倍数,在512~65536之间。默认是 2048public static String encodeBASE64(byte[] bstr)
bstr
- public static byte[] decodeBASE64(String str)
str
- Copyright © 2018. All rights reserved.