类 RSAUtil
java.lang.Object
org.anyline.util.encrypt.RSAUtil
-
字段概要
字段 -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明static String密钥生成base64字符static KeyPaircreate()static KeyPaircreate(int size) 创建密钥对 返回密钥对后可以getPrivate()获取私钥或getPublic()获取公钥 获取公钥私钥后可以通过base64(key)生成String用来交换密钥static RSAPrivateKeycreatePrivateKey(File file) 从文件中提取私钥static RSAPrivateKey从输入流中提取私钥static RSAPrivateKeycreatePrivateKey(String base64) 创建私钥static RSAPublicKeycreatePublicKey(File file) 从文件中提取公钥static RSAPublicKey从输入流中提取公钥static RSAPublicKeycreatePublicKey(String base64) 创建公钥static Stringstatic Stringdecrypt(String data, RSAPublicKey key) 公钥解密static Stringdecrypt(String data, PrivateKey key) 私钥解密static Stringstatic Stringencrypt(String data, RSAPrivateKey key) 私钥加密(加密应该用公钥)static String公钥加密static Stringsign(byte[] data, PrivateKey key) 用私钥对信息生成数字签名static Stringstatic Stringsign(String data, PrivateKey key) static booleanstatic boolean校验数字签名static boolean校验数字签名static boolean校验数字签名
-
字段详细资料
-
构造器详细资料
-
RSAUtil
public RSAUtil()
-
-
方法详细资料
-
create
创建密钥对 返回密钥对后可以getPrivate()获取私钥或getPublic()获取公钥 获取公钥私钥后可以通过base64(key)生成String用来交换密钥- 参数:
size- 位数- 返回:
- KeyPair
-
create
-
base64
密钥生成base64字符- 参数:
key- 密钥- 返回:
- String
-
createPublicKey
public static RSAPublicKey createPublicKey(String base64) throws NoSuchAlgorithmException, InvalidKeySpecException 创建公钥- 参数:
base64- 密钥字符串(经过base64编码)- 返回:
- RSAPublicKey
- 抛出:
NoSuchAlgorithmException- NoSuchAlgorithmExceptionInvalidKeySpecException- InvalidKeySpecException
-
createPrivateKey
public static RSAPrivateKey createPrivateKey(String base64) throws NoSuchAlgorithmException, InvalidKeySpecException 创建私钥- 参数:
base64- 密钥字符串(经过base64编码)- 返回:
- RSAPrivateKey
- 抛出:
NoSuchAlgorithmException- NoSuchAlgorithmExceptionInvalidKeySpecException- InvalidKeySpecException
-
encrypt
公钥加密- 参数:
data- datakey- RSA 公钥- 返回:
- String
- 抛出:
Exception- 异常 Exception
-
encrypt
- 抛出:
Exception
-
decrypt
私钥解密- 参数:
data- datakey- RSA 私钥- 返回:
- String
- 抛出:
Exception- 异常 Exception
-
decrypt
- 抛出:
Exception
-
encrypt
私钥加密(加密应该用公钥)- 参数:
data- datakey- RSA 私钥- 返回:
- String
- 抛出:
Exception- 异常 Exception
-
decrypt
公钥解密- 参数:
data- datakey- RSA 公钥- 返回:
- String
- 抛出:
Exception- 异常 Exception
-
sign
用私钥对信息生成数字签名- 参数:
data- 已加密数据key- 私钥(BASE64编码)- 返回:
- String
- 抛出:
Exception- 异常 Exception
-
sign
- 抛出:
Exception
-
sign
- 抛出:
Exception
-
verify
校验数字签名- 参数:
data- 已加密数据key- 公钥(BASE64编码)sign- 数字签名- 返回:
- boolean
- 抛出:
Exception- 异常 Exception
-
verify
- 抛出:
Exception
-
verify
校验数字签名- 参数:
data- 已加密数据key- 公钥(BASE64编码)sign- 数字签名- 返回:
- boolean
- 抛出:
Exception- 异常 Exception
-
verify
校验数字签名- 参数:
data- 已加密数据key- 公钥sign- 数字签名- 返回:
- boolean
- 抛出:
Exception- 异常 Exception
-
createPrivateKey
从文件中提取私钥- 参数:
file- 密钥文件- 返回:
- RSAPrivateKey
- 抛出:
Exception
-
createPublicKey
从文件中提取公钥- 参数:
file- file- 返回:
- RSAPublicKey
- 抛出:
Exception
-
createPublicKey
从输入流中提取公钥- 参数:
is- 输入流- 返回:
- RSAPublicKey
- 抛出:
Exception
-
createPrivateKey
从输入流中提取私钥- 参数:
is- 输入流- 返回:
- RSAPublicKey
- 抛出:
Exception
-