mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
add update method
This commit is contained in:
parent
42b600b682
commit
dff0bf6490
@ -3,9 +3,10 @@
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
|
||||
# 5.6.8 (2021-06-09)
|
||||
# 5.6.8 (2021-06-10)
|
||||
|
||||
### 🐣新特性
|
||||
* 【crypto 】 SymmetricCrypto增加update方法(pr#1642@Github)
|
||||
|
||||
### 🐞Bug修复
|
||||
|
||||
|
@ -198,31 +198,14 @@ public class SymmetricCrypto implements Serializable {
|
||||
return this;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------- Encrypt
|
||||
|
||||
/**
|
||||
* 加密
|
||||
*
|
||||
* @param data 被加密的bytes
|
||||
* @return 加密后的bytes
|
||||
*/
|
||||
public byte[] encrypt(byte[] data) {
|
||||
lock.lock();
|
||||
try {
|
||||
final Cipher cipher = initCipher(Cipher.ENCRYPT_MODE);
|
||||
return cipher.doFinal(paddingDataWithZero(data, cipher.getBlockSize()));
|
||||
} catch (Exception e) {
|
||||
throw new CryptoException(e);
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
// --------------------------------------------------------------------------------- Update
|
||||
|
||||
/**
|
||||
* 更新数据,分组加密中间结果可以当作随机数
|
||||
*
|
||||
* @param data 被加密的bytes
|
||||
* @return update之后的bytes
|
||||
* @since 5.6.8
|
||||
*/
|
||||
public byte[] update(byte[] data) {
|
||||
lock.lock();
|
||||
@ -241,11 +224,32 @@ public class SymmetricCrypto implements Serializable {
|
||||
*
|
||||
* @param data 被加密的bytes
|
||||
* @return update之后的hex数据
|
||||
* @since 5.6.8
|
||||
*/
|
||||
public String updateHex(byte[] data) {
|
||||
return HexUtil.encodeHexStr(update(data));
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------- Encrypt
|
||||
|
||||
/**
|
||||
* 加密
|
||||
*
|
||||
* @param data 被加密的bytes
|
||||
* @return 加密后的bytes
|
||||
*/
|
||||
public byte[] encrypt(byte[] data) {
|
||||
lock.lock();
|
||||
try {
|
||||
final Cipher cipher = initCipher(Cipher.ENCRYPT_MODE);
|
||||
return cipher.doFinal(paddingDataWithZero(data, cipher.getBlockSize()));
|
||||
} catch (Exception e) {
|
||||
throw new CryptoException(e);
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 加密,针对大数据量,可选结束后是否关闭流
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user