public abstract class RSAUtils extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
private static String |
PEM_PRIVATE_KEY |
private static String |
PEM_PUBLIC_KEY |
private static String |
RSA_ALGORITHM |
static String |
RSA_DEFAULT_TRANSFORMATION |
| 构造器和说明 |
|---|
RSAUtils() |
| 限定符和类型 | 方法和说明 |
|---|---|
static byte[] |
decryptData(byte[] cipher_data,
int data_offset,
int data_len,
Key key,
String transformation) |
static byte[] |
decryptData(byte[] cipher_data,
Key key,
String transformation) |
static byte[] |
encryptData(byte[] plaint_data,
int data_offset,
int data_len,
Key key,
String transformation) |
static byte[] |
encryptData(byte[] plaint_data,
Key key,
String transformation) |
static KeyPair |
generateKeyPair(int keySize)
产生密钥对
|
static PrivateKey |
parsePrivateKey(String key) |
static PrivateKey |
parsePrivateKeyFromPEM(String pem) |
static PublicKey |
parsePublicKey(String key) |
static PublicKey |
parsePublicKeyFromPEM(String pem)
从PEM格式中获得RSA公钥
|
static byte[] |
signData(byte[] digest,
int offset,
int len,
PrivateKey privkey,
String algorithm) |
static byte[] |
signData(byte[] digest,
PrivateKey privkey,
String algorithm) |
static String |
toPem(Key key) |
static boolean |
verifySign(byte[] digest,
byte[] sign,
PublicKey pubkey,
String algorithm) |
public static KeyPair generateKeyPair(int keySize)
keySize - 密钥长度KeyPairpublic static PublicKey parsePublicKeyFromPEM(String pem)
pem - 传入的PEM格式PublicKeypublic static PrivateKey parsePrivateKey(String key)
public static PrivateKey parsePrivateKeyFromPEM(String pem)
pem - PEM格式PrivateKeypublic static boolean verifySign(byte[] digest,
byte[] sign,
PublicKey pubkey,
String algorithm)
throws InvalidKeyException,
SignatureException
digest - 原始数据sign - 签名数据pubkey - 公钥algorithm - 签名算法InvalidKeyExceptionSignatureExceptionpublic static byte[] signData(byte[] digest,
PrivateKey privkey,
String algorithm)
throws InvalidKeyException,
SignatureException
digest - 待签名数据privkey - RSA私钥algorithm - 签名数据InvalidKeyExceptionSignatureExceptionpublic static byte[] signData(byte[] digest,
int offset,
int len,
PrivateKey privkey,
String algorithm)
throws InvalidKeyException,
SignatureException
public static byte[] decryptData(byte[] cipher_data,
Key key,
String transformation)
throws InvalidKeyException,
NoSuchPaddingException,
IllegalBlockSizeException,
BadPaddingException
cipher_data - 密文key - 密钥InvalidKeyExceptionNoSuchPaddingExceptionIllegalBlockSizeExceptionBadPaddingExceptionpublic static byte[] decryptData(byte[] cipher_data,
int data_offset,
int data_len,
Key key,
String transformation)
throws InvalidKeyException,
NoSuchPaddingException,
IllegalBlockSizeException,
BadPaddingException
cipher_data - 密文块data_offset - 开始索引data_len - 数据长度key - 密钥InvalidKeyExceptionNoSuchPaddingExceptionIllegalBlockSizeExceptionBadPaddingExceptionpublic static byte[] encryptData(byte[] plaint_data,
Key key,
String transformation)
throws InvalidKeyException,
NoSuchPaddingException,
IllegalBlockSizeException,
BadPaddingException
plaint_data - 明文key - 密钥InvalidKeyExceptionNoSuchPaddingExceptionIllegalBlockSizeExceptionBadPaddingExceptionpublic static byte[] encryptData(byte[] plaint_data,
int data_offset,
int data_len,
Key key,
String transformation)
throws InvalidKeyException,
NoSuchPaddingException,
IllegalBlockSizeException,
BadPaddingException
plaint_data - 明文块data_offset - 开始索引data_len - 数据长度key - 密钥InvalidKeyExceptionNoSuchPaddingExceptionIllegalBlockSizeExceptionBadPaddingExceptionCopyright © 2022. All rights reserved.