public class Cipher extends Object
Modifier and Type | Class and Description |
---|---|
class |
Cipher.KeyPairStore
保存非对称加密算法的公钥和私钥
|
Constructor and Description |
---|
Cipher(String algorithm)
构造函数
|
Cipher(String algorithm,
String mode,
String fillMode)
构造函数
|
Modifier and Type | Method and Description |
---|---|
byte[] |
decrypt(byte[] data)
加密算法
|
byte[] |
encrypt(byte[] data)
加密算法
|
byte[] |
generateSymmetryKey()
生成一个对称加密的密钥
|
Cipher.KeyPairStore |
generatPairKey()
生成一对非对称加密的公钥和私钥
|
PrivateKey |
loadPrivateKey(byte[] keyBytes)
读取非对称加密的私钥
|
PublicKey |
loadPublicKey(byte[] keyBytes)
读取非对称加密的公钥
|
SecretKey |
loadSymmetryKey(byte[] keyBytes)
读取对称加密的密钥
|
public Cipher(String algorithm) throws NoSuchAlgorithmException
algorithm
- 加密算法名称NoSuchAlgorithmException
- 算法指定异常public Cipher(String algorithm, String mode, String fillMode) throws NoSuchAlgorithmException
algorithm
- 加密算法名称mode
- 加密形式fillMode
- 密钥填充方式NoSuchAlgorithmException
- 算法指定异常public byte[] generateSymmetryKey() throws NoSuchAlgorithmException
NoSuchAlgorithmException
- 算法指定异常public Cipher.KeyPairStore generatPairKey() throws NoSuchAlgorithmException
NoSuchAlgorithmException
- 算法指定异常public SecretKey loadSymmetryKey(byte[] keyBytes)
keyBytes
- 密钥public PublicKey loadPublicKey(byte[] keyBytes) throws NoSuchAlgorithmException, InvalidKeySpecException
keyBytes
- 公钥NoSuchAlgorithmException
- 算法异常InvalidKeySpecException
- 密钥异常public PrivateKey loadPrivateKey(byte[] keyBytes) throws NoSuchAlgorithmException, InvalidKeySpecException
keyBytes
- 私钥NoSuchAlgorithmException
- 算法异常InvalidKeySpecException
- 密钥异常public byte[] encrypt(byte[] data) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException
data
- 明文NoSuchPaddingException
- 填充模式异常NoSuchAlgorithmException
- 算法异常InvalidKeyException
- 密钥异常BadPaddingException
- 填充操作异常IllegalBlockSizeException
- 异常public byte[] decrypt(byte[] data) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException
data
- 密文NoSuchPaddingException
- 填充模式异常NoSuchAlgorithmException
- 算法异常InvalidKeyException
- 密钥异常BadPaddingException
- 填充操作异常IllegalBlockSizeException
- 异常Copyright © 2020 Voovan. All rights reserved.