public final class RSAEncrypt extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
static int |
DEFAULT_KEY_SIZE |
| 限定符和类型 | 方法和说明 |
|---|---|
static RSAPrivateKey |
bytesToRSAPrivateKey(byte[] keyBytes)
将符合PKCS#8格式的密钥数据转换成RSAPrivateKey对象
|
static RSAPublicKey |
bytesToRSAPublicKey(byte[] keyBytes)
将符合X.509格式的数据密钥转换成RSAPublicKey对象
|
static byte[] |
decrypt(RSAPrivateKey privateKey,
byte[] cipherData)
公钥/私钥解密过程
|
static byte[] |
decrypt(RSAPublicKey publicKey,
byte[] cipherData)
公钥解密过程
|
static byte[] |
encrypt(RSAPrivateKey privateKey,
byte[] plainTextData)
私钥加密
|
static byte[] |
encrypt(RSAPublicKey publicKey,
byte[] plainTextData)
公钥加密
|
static KeyPair |
getKeyPair(int keySize)
生成一对RSA密钥
|
public static KeyPair getKeyPair(int keySize)
keySize - 密钥长度public static RSAPublicKey bytesToRSAPublicKey(byte[] keyBytes) throws InvalidKeySpecException
keyBytes - 密钥数据InvalidKeySpecException - 当密钥数据无效时抛出public static RSAPrivateKey bytesToRSAPrivateKey(byte[] keyBytes) throws InvalidKeySpecException
keyBytes - 密钥数据InvalidKeySpecException - 当密钥数据无效时抛出public static byte[] encrypt(RSAPublicKey publicKey, byte[] plainTextData) throws NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException
publicKey - 公钥plainTextData - 明文数据NoSuchPaddingException - 不支持的填充方式InvalidKeyException - 无效密钥BadPaddingException - 密文损坏IllegalBlockSizeException - 密文长度错误public static byte[] encrypt(RSAPrivateKey privateKey, byte[] plainTextData) throws NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException
privateKey - 私钥plainTextData - 明文数据NoSuchPaddingException - 不支持的填充方式InvalidKeyException - 无效密钥BadPaddingException - 密文损坏IllegalBlockSizeException - 密文长度错误public static byte[] decrypt(RSAPrivateKey privateKey, byte[] cipherData) throws NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException
privateKey - 私钥cipherData - 密文数据NoSuchPaddingException - 不支持的填充方式InvalidKeyException - 无效密钥BadPaddingException - 密文损坏IllegalBlockSizeException - 密文长度错误public static byte[] decrypt(RSAPublicKey publicKey, byte[] cipherData) throws NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException
publicKey - 公钥cipherData - 密文数据NoSuchPaddingException - 不支持的填充方式InvalidKeyException - 无效密钥BadPaddingException - 密文损坏IllegalBlockSizeException - 密文长度错误Copyright © 2020. All rights reserved.