public final class RsaUtil extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
static String |
KEY_ALGORITHM |
static String |
SIGNATURE_ALGORITHM |
| 限定符和类型 | 方法和说明 |
|---|---|
static byte[] |
decrypt(byte[] encrypted,
String privateKeyStr)
解密
|
static byte[] |
encrypt(byte[] plaintext,
String publicKeyStr)
加密
|
static byte[] |
extractKey(String originKey)
提取公钥或私钥通过 Base64 解码后的字节数组
|
static RSAPrivateKey |
getPrivateKey(String key)
转换私钥
|
static RSAPublicKey |
getPublicKey(String key)
获取公钥,返回类型为
PublicKey |
static byte[] |
sign(byte[] data,
String privateKeyStr)
签名
|
static boolean |
verify(byte[] data,
byte[] sign,
String publicKeyStr)
校验签名
|
public static RSAPublicKey getPublicKey(String key) throws Exception
PublicKeykey - String PublicKeyException - 转换异常public static RSAPrivateKey getPrivateKey(String key) throws Exception
key - String PrivateKeyException - 转换异常public static byte[] extractKey(String originKey)
originKey - 原始公钥或私钥public static byte[] sign(byte[] data,
String privateKeyStr)
throws Exception
data - 数据privateKeyStr - 私钥Exception - 签名异常public static boolean verify(byte[] data,
byte[] sign,
String publicKeyStr)
throws Exception
data - 数据sign - 签名publicKeyStr - 公钥Exception - 校验异常public static byte[] encrypt(byte[] plaintext,
String publicKeyStr)
throws Exception
plaintext - 要加密的数据publicKeyStr - 公钥Exception - 加密异常Copyright © 2021. All rights reserved.