public class RSACommon extends Object
| Constructor and Description |
|---|
RSACommon() |
| Modifier and Type | Method and Description |
|---|---|
static byte[] |
decrypt(byte[] privateKey,
byte[] content)
使用RSA私钥解密
|
static byte[] |
encrypt(byte[] publicKey,
byte[] content)
使用RSA公钥加密
|
static boolean |
isKeyPair(byte[] publicKey,
byte[] privateKey)
公私钥对是否匹配
|
static byte[] |
sign(byte[] privateKey,
byte[] content)
私钥签名
|
static byte[] |
sign(byte[] privateKey,
byte[] content,
String algorithm)
使用指定算法签名,默认SHA256withRSA
|
static boolean |
verify(byte[] publicKey,
byte[] content,
byte[] signature) |
static boolean |
verify(byte[] publicKey,
byte[] content,
byte[] signature,
String algorithm)
公钥验签
|
public static final boolean isKeyPair(byte[] publicKey,
byte[] privateKey)
throws InvalidKeySpecException,
NoSuchAlgorithmException,
SignatureException,
InvalidKeyException
publicKey - privateKey - InvalidKeySpecExceptionNoSuchAlgorithmExceptionSignatureExceptionInvalidKeyExceptionpublic static byte[] sign(byte[] privateKey,
byte[] content)
throws InvalidKeySpecException,
NoSuchAlgorithmException,
InvalidKeyException,
SignatureException
privateKey - content - InvalidKeySpecExceptionNoSuchAlgorithmExceptionInvalidKeyExceptionSignatureExceptionpublic static byte[] sign(byte[] privateKey,
byte[] content,
String algorithm)
throws InvalidKeySpecException,
NoSuchAlgorithmException,
InvalidKeyException,
SignatureException
privateKey - content - algorithm - InvalidKeySpecExceptionNoSuchAlgorithmExceptionInvalidKeyExceptionSignatureExceptionpublic static boolean verify(byte[] publicKey,
byte[] content,
byte[] signature)
throws InvalidKeySpecException,
NoSuchAlgorithmException,
InvalidKeyException,
SignatureException
public static boolean verify(byte[] publicKey,
byte[] content,
byte[] signature,
String algorithm)
throws InvalidKeySpecException,
NoSuchAlgorithmException,
InvalidKeyException,
SignatureException
publicKey - content - signature - InvalidKeySpecExceptionNoSuchAlgorithmExceptionInvalidKeyExceptionSignatureExceptionpublic static final byte[] encrypt(byte[] publicKey,
byte[] content)
throws NoSuchPaddingException,
NoSuchAlgorithmException,
InvalidKeySpecException,
InvalidKeyException,
BadPaddingException,
IllegalBlockSizeException,
IOException
publicKey - content - NoSuchPaddingExceptionNoSuchAlgorithmExceptionInvalidKeySpecExceptionInvalidKeyExceptionBadPaddingExceptionIllegalBlockSizeExceptionIOExceptionpublic static final byte[] decrypt(byte[] privateKey,
byte[] content)
throws NoSuchPaddingException,
NoSuchAlgorithmException,
InvalidKeySpecException,
InvalidKeyException,
BadPaddingException,
IllegalBlockSizeException,
IOException
privateKey - content - NoSuchPaddingExceptionNoSuchAlgorithmExceptionInvalidKeySpecExceptionInvalidKeyExceptionBadPaddingExceptionIllegalBlockSizeExceptionIOExceptionCopyright © 2020. All rights reserved.