add update method

This commit is contained in:
Looly 2021-06-10 11:52:44 +08:00
parent 42b600b682
commit dff0bf6490
2 changed files with 25 additions and 20 deletions

View File

@ -3,9 +3,10 @@
------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------
# 5.6.8 (2021-06-09) # 5.6.8 (2021-06-10)
### 🐣新特性 ### 🐣新特性
* 【crypto 】 SymmetricCrypto增加update方法pr#1642@Github
### 🐞Bug修复 ### 🐞Bug修复

View File

@ -198,31 +198,14 @@ public class SymmetricCrypto implements Serializable {
return this; return this;
} }
// --------------------------------------------------------------------------------- Encrypt // --------------------------------------------------------------------------------- Update
/**
* 加密
*
* @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();
}
}
/** /**
* 更新数据分组加密中间结果可以当作随机数 * 更新数据分组加密中间结果可以当作随机数
* *
* @param data 被加密的bytes * @param data 被加密的bytes
* @return update之后的bytes * @return update之后的bytes
* @since 5.6.8
*/ */
public byte[] update(byte[] data) { public byte[] update(byte[] data) {
lock.lock(); lock.lock();
@ -241,11 +224,32 @@ public class SymmetricCrypto implements Serializable {
* *
* @param data 被加密的bytes * @param data 被加密的bytes
* @return update之后的hex数据 * @return update之后的hex数据
* @since 5.6.8
*/ */
public String updateHex(byte[] data) { public String updateHex(byte[] data) {
return HexUtil.encodeHexStr(update(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();
}
}
/** /**
* 加密针对大数据量可选结束后是否关闭流 * 加密针对大数据量可选结束后是否关闭流
* *