public class RSAUtils extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
static String |
PRIVATE_KEY
获取私钥的KEY
|
static String |
PUBLIC_KEY
获取公钥的KEY
|
| 构造器和说明 |
|---|
RSAUtils() |
| 限定符和类型 | 方法和说明 |
|---|---|
static byte[] |
decrypt(Key key,
byte[] input)
解密
|
static byte[] |
encrypt(Key key,
byte[] input)
加密
|
static Map<String,RSAKey> |
genKeyPair()
生成RSA算法的密钥对
|
static Map<String,String> |
genKeyPairBase64String()
获取字符串key 对
|
static PrivateKey |
getPrivateKey(File file)
通过文件获取私钥对象
|
static PrivateKey |
getPrivateKey(String strPrivateKey)
通过字符串获取私钥对象
|
static PublicKey |
getPublicKey(File file)
从公钥文件中加载获取公钥Java对象
|
static PublicKey |
getPublicKey(String strPublicKey)
从公钥字符串加载获取公钥Java对象
|
static String |
key2String(Key key)
将Java对象的公钥或者私钥转换为字符串
|
static void |
main(String[] args) |
public static Map<String,RSAKey> genKeyPair() throws NoSuchAlgorithmException
NoSuchAlgorithmException - 获取密钥对可能发生的异常public static Map<String,String> genKeyPairBase64String() throws NoSuchAlgorithmException
NoSuchAlgorithmExceptionpublic static byte[] encrypt(Key key, byte[] input) throws Exception
key - 加密使用的[公钥/私钥]input - 需要加密的明文Exception - 加密过程中可能发生的异常public static byte[] decrypt(Key key, byte[] input) throws Exception
key - 对应解密的[公钥或私钥]input - 需要解密的加密信息Exception - 解密过程中可能发生的异常public static PrivateKey getPrivateKey(File file) throws Exception
file - 私钥文件Exception - 从文件私钥获取私钥Java对象过程中可能发生的异常public static PrivateKey getPrivateKey(String strPrivateKey) throws Exception
strPrivateKey - 字符串的私钥Exception - 从字符串私钥获取私钥Java对象过程中可能发生的异常public static PublicKey getPublicKey(File file) throws Exception
file - 公钥文件Exception - 获取过程中可能发生的异常public static PublicKey getPublicKey(String strPublicKey) throws Exception
strPublicKey - 公钥字符串Exception - 获取过程中可能发生的异常Copyright © 2021. All rights reserved.