public class Crypto extends Object implements Encryptor, Decryptor, Serializable
| Constructor and Description |
|---|
Crypto(org.aoju.bus.core.lang.Algorithm algorithm)
构造,使用随机密钥
|
Crypto(org.aoju.bus.core.lang.Algorithm algorithm,
byte[] key)
构造
|
Crypto(org.aoju.bus.core.lang.Algorithm algorithm,
SecretKey key)
构造
|
Crypto(String algorithm)
构造,使用随机密钥
|
Crypto(String algorithm,
byte[] key)
构造
|
Crypto(String algorithm,
SecretKey key)
构造
|
Crypto(String algorithm,
SecretKey key,
AlgorithmParameterSpec paramsSpec)
构造
|
| Modifier and Type | Method and Description |
|---|---|
byte[] |
decrypt(byte[] bytes)
解密
|
void |
decrypt(InputStream data,
OutputStream out,
boolean isClose)
解密,针对大数据量,结束后不关闭流
|
byte[] |
encrypt(byte[] data)
加密
|
void |
encrypt(InputStream data,
OutputStream out,
boolean isClose)
加密,针对大数据量,可选结束后是否关闭流
|
Cipher |
getCipher()
获得加密或解密器
|
SecretKey |
getSecretKey()
获得对称密钥
|
Crypto |
init(String algorithm,
SecretKey key)
初始化
|
Crypto |
setIv(byte[] iv)
设置偏移向量
|
Crypto |
setIv(IvParameterSpec iv)
设置偏移向量
|
Crypto |
setMode(Mode.Cipher mode)
初始化模式并清空数据
|
Crypto |
setParams(AlgorithmParameterSpec params)
设置
AlgorithmParameterSpec,通常用于加盐或偏移向量 |
byte[] |
update(byte[] data)
更新数据,分组加密中间结果可以当作随机数
第一次更新数据前需要调用
setMode(Mode.Cipher)初始化加密或解密模式,然后每次更新数据都是累加模式 |
String |
updateHex(byte[] data)
更新数据,分组加密中间结果可以当作随机数
第一次更新数据前需要调用
setMode(Mode.Cipher)初始化加密或解密模式,然后每次更新数据都是累加模式 |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitencrypt, encrypt, encrypt, encrypt, encryptBase64, encryptBase64, encryptBase64, encryptBase64, encryptBase64, encryptHex, encryptHex, encryptHex, encryptHex, encryptHexdecrypt, decrypt, decryptStr, decryptStr, decryptStr, decryptStr, decryptStr, decryptStrpublic Crypto(org.aoju.bus.core.lang.Algorithm algorithm)
algorithm - Algorithmpublic Crypto(String algorithm)
algorithm - 算法,可以是"algorithm/mode/padding"或者"algorithm"public Crypto(org.aoju.bus.core.lang.Algorithm algorithm,
byte[] key)
algorithm - 算法 Algorithmkey - 自定义KEYpublic Crypto(org.aoju.bus.core.lang.Algorithm algorithm,
SecretKey key)
algorithm - 算法 Algorithmkey - 自定义KEYpublic Crypto(String algorithm, byte[] key)
algorithm - 算法key - 密钥public Crypto(String algorithm, SecretKey key, AlgorithmParameterSpec paramsSpec)
algorithm - 算法key - 密钥paramsSpec - 算法参数,例如加盐等public Crypto init(String algorithm, SecretKey key)
algorithm - 算法key - 密钥,如果为null自动生成一个keypublic SecretKey getSecretKey()
public Cipher getCipher()
public Crypto setParams(AlgorithmParameterSpec params)
AlgorithmParameterSpec,通常用于加盐或偏移向量params - AlgorithmParameterSpecpublic Crypto setIv(IvParameterSpec iv)
iv - IvParameterSpec偏移向量public Crypto setIv(byte[] iv)
iv - 偏移向量,加盐public Crypto setMode(Mode.Cipher mode)
mode - 模式枚举public byte[] update(byte[] data)
setMode(Mode.Cipher)初始化加密或解密模式,然后每次更新数据都是累加模式data - 被加密的bytespublic String updateHex(byte[] data)
setMode(Mode.Cipher)初始化加密或解密模式,然后每次更新数据都是累加模式data - 被加密的bytespublic byte[] encrypt(byte[] data)
Encryptorpublic void encrypt(InputStream data, OutputStream out, boolean isClose) throws org.aoju.bus.core.lang.exception.CryptoException
Encryptorpublic byte[] decrypt(byte[] bytes)
Decryptorpublic void decrypt(InputStream data, OutputStream out, boolean isClose) throws org.aoju.bus.core.lang.exception.CryptoException
DecryptorCopyright © 2021. All rights reserved.