public class RSAUtil extends Object
| 构造器和说明 |
|---|
RSAUtil() |
| 限定符和类型 | 方法和说明 |
|---|---|
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 void |
genKeyPair(String filePath)
随机生成密钥对
|
static String |
loadPrivateKeyByFile(String path)
从文件中加载私钥
|
static RSAPrivateKey |
loadPrivateKeyByStr(String privateKeyStr)
从字符串中加载私钥
|
static String |
loadPublicKeyByFile(String path)
从文件中加载公钥
|
static RSAPublicKey |
loadPublicKeyByStr(String publicKeyStr)
从字符串中加载公钥
|
public static void genKeyPair(String filePath) throws IOException
filePath - IOExceptionpublic static String loadPublicKeyByFile(String path) throws IOException
path - IOExceptionpublic static RSAPublicKey loadPublicKeyByStr(String publicKeyStr) throws NoSuchAlgorithmException, InvalidKeySpecException
publicKeyStr - NoSuchAlgorithmExceptionInvalidKeySpecExceptionpublic static String loadPrivateKeyByFile(String path) throws IOException
path - IOExceptionpublic static RSAPrivateKey loadPrivateKeyByStr(String privateKeyStr) throws NoSuchAlgorithmException, InvalidKeySpecException
privateKeyStr - NoSuchAlgorithmExceptionInvalidKeySpecExceptionpublic static byte[] encrypt(RSAPublicKey publicKey, byte[] plainTextData) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException
publicKey - plainTextData - NoSuchAlgorithmExceptionNoSuchPaddingExceptionInvalidKeyExceptionIllegalBlockSizeExceptionBadPaddingExceptionpublic static byte[] encrypt(RSAPrivateKey privateKey, byte[] plainTextData) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException
privateKey - plainTextData - NoSuchAlgorithmExceptionNoSuchPaddingExceptionInvalidKeyExceptionIllegalBlockSizeExceptionBadPaddingExceptionpublic static byte[] decrypt(RSAPrivateKey privateKey, byte[] cipherData) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException
privateKey - cipherData - NoSuchAlgorithmExceptionNoSuchPaddingExceptionInvalidKeyExceptionIllegalBlockSizeExceptionBadPaddingExceptionpublic static byte[] decrypt(RSAPublicKey publicKey, byte[] cipherData) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException
publicKey - cipherData - NoSuchAlgorithmExceptionNoSuchPaddingExceptionInvalidKeyExceptionIllegalBlockSizeExceptionBadPaddingExceptionCopyright © 2021. All rights reserved.