public class RSAUtil extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
static String |
CHARSET |
static String |
RSA_ALGORITHM |
static String |
SIGNATURE_ALGORITHM |
| 构造器和说明 |
|---|
RSAUtil() |
| 限定符和类型 | 方法和说明 |
|---|---|
static Map<String,String> |
createKeys(int keySize) |
static RSAPrivateKey |
getPrivateKey(File file,
String keyAlgorithm)
从文件中提取私钥
|
static RSAPrivateKey |
getPrivateKey(InputStream inputStream,
String keyAlgorithm) |
static RSAPrivateKey |
getPrivateKey(String privateKey)
得到私钥
|
static RSAPublicKey |
getPublicKey(File file) |
static RSAPublicKey |
getPublicKey(InputStream inputStream) |
static RSAPublicKey |
getPublicKey(String publicKey)
得到公钥
|
static String |
privateDecrypt(String data,
RSAPrivateKey privateKey)
私钥解密
|
static String |
privateEncrypt(String data,
RSAPrivateKey privateKey)
私钥加密
|
static String |
publicDecrypt(String data,
RSAPublicKey publicKey)
公钥解密
|
static String |
publicEncrypt(String data,
RSAPublicKey publicKey)
公钥加密
|
static String |
sign(byte[] data,
String privateKey)
用私钥对信息生成数字签名
|
static String |
sign(String data,
String privateKey) |
static boolean |
verify(byte[] data,
String publicKey,
String sign)
校验数字签名
|
static boolean |
verify(String data,
String publicKey,
String sign) |
public static RSAPublicKey getPublicKey(String publicKey) throws NoSuchAlgorithmException, InvalidKeySpecException
publicKey - 密钥字符串(经过base64编码)NoSuchAlgorithmException - NoSuchAlgorithmExceptionInvalidKeySpecException - InvalidKeySpecExceptionpublic static RSAPrivateKey getPrivateKey(String privateKey) throws NoSuchAlgorithmException, InvalidKeySpecException
privateKey - 密钥字符串(经过base64编码)NoSuchAlgorithmException - NoSuchAlgorithmExceptionInvalidKeySpecException - InvalidKeySpecExceptionpublic static String publicEncrypt(String data, RSAPublicKey publicKey) throws Exception
data - datapublicKey - publicKeyException - Exceptionpublic static String privateDecrypt(String data, RSAPrivateKey privateKey) throws Exception
data - dataprivateKey - privateKeyException - Exceptionpublic static String privateEncrypt(String data, RSAPrivateKey privateKey) throws Exception
data - dataprivateKey - privateKeyException - Exceptionpublic static String publicDecrypt(String data, RSAPublicKey publicKey) throws Exception
data - datapublicKey - publicKeyException - Exceptionpublic static String sign(byte[] data, String privateKey) throws Exception
data - 已加密数据privateKey - 私钥(BASE64编码)Exception - Exceptionpublic static boolean verify(byte[] data,
String publicKey,
String sign)
throws Exception
校验数字签名
data - 已加密数据publicKey - 公钥(BASE64编码)sign - 数字签名Exception - Exceptionpublic static boolean verify(String data, String publicKey, String sign) throws Exception
Exceptionpublic static RSAPrivateKey getPrivateKey(File file, String keyAlgorithm)
file - filekeyAlgorithm - keyAlgorithmpublic static RSAPublicKey getPublicKey(File file)
public static RSAPublicKey getPublicKey(InputStream inputStream) throws Exception
Exceptionpublic static RSAPrivateKey getPrivateKey(InputStream inputStream, String keyAlgorithm) throws Exception
ExceptionCopyright © 2022. All rights reserved.