public class RsaUtil extends SecurityUtil
| 限定符和类型 | 字段和说明 |
|---|---|
String |
algorithm |
String |
SIGN_ALGORITHMS
签名算法
|
log| 构造器和说明 |
|---|
RsaUtil() |
| 限定符和类型 | 方法和说明 |
|---|---|
byte[] |
decryptData(PrivateKey key,
byte[] data)
使用私钥解密数据
|
byte[] |
decryptData(PublicKey key,
byte[] data)
使用公钥解密数据
|
byte[] |
encryptData(PrivateKey key,
byte[] data)
使用私钥加密数据
|
byte[] |
encryptData(PublicKey key,
byte[] data)
使用公钥加密数据
|
KeyPair |
getKeyPair()
获取一个新的密钥对,默认密钥长度1024
|
KeyPair |
getKeyPair(int keysize)
获取一个新的密钥对
|
PrivateKey |
getPrivateKey_PKCS8Encoded(byte[] keyBytes)
根据私钥字符串获取私钥
Only RSAPrivate(Crt)KeySpec and PKCS8EncodedKeySpec supported for RSA private keys
|
PublicKey |
getPublicKey_X509Encoded(byte[] keyBytes)
根据公钥字符串获取公钥
Only RSAPublicKeySpec and X509EncodedKeySpec supported for RSA public keys
|
KeyPair |
getRandomKeyPair(int keySize)
使用默认系统随机源和确定密钥大小来生成密钥对。
|
static void |
main(String[] args) |
byte[] |
sign(byte[] content,
PrivateKey privateKey)
RSA签名
|
boolean |
signVerify(byte[] content,
byte[] sign,
PublicKey pubKey)
RSA验签名检查
|
PrivateKey |
unwrapPrivateKeyByKey(byte[] key,
Key unwrapKey)
使用密钥解包密钥
|
PublicKey |
unwrapPublicKeyByKey(byte[] key,
Key unwrapKey)
使用密钥解包密钥
|
byte[] |
wrapKeyByKey(Key key,
Key wrapKey)
用密钥包裹密钥
|
Base64Decode, Base64Decode, Base64Encodepublic KeyPair getRandomKeyPair(int keySize)
NoSuchAlgorithmExceptionpublic KeyPair getKeyPair()
public KeyPair getKeyPair(int keysize)
public byte[] encryptData(PublicKey key, byte[] data)
key - data - 待加密数据public byte[] encryptData(PrivateKey key, byte[] data)
key - 私钥data - 待加密数据public byte[] decryptData(PublicKey key, byte[] data)
key - 公钥data - 被私钥加密过的数据public byte[] decryptData(PrivateKey key, byte[] data)
key - 私钥data - 被公钥加密的数据public PrivateKey unwrapPrivateKeyByKey(byte[] key, Key unwrapKey)
key - unwrapKey - public PublicKey unwrapPublicKeyByKey(byte[] key, Key unwrapKey)
key - unwrapKey - public PublicKey getPublicKey_X509Encoded(byte[] keyBytes)
publicKey - public PrivateKey getPrivateKey_PKCS8Encoded(byte[] keyBytes)
privateKey - public byte[] sign(byte[] content,
PrivateKey privateKey)
content - 待签名数据privateKey - 商户私钥public boolean signVerify(byte[] content,
byte[] sign,
PublicKey pubKey)
content - 待签名数据sign - 签名值publicKey - 分配给开发商公钥Copyright © 2020. All rights reserved.