对称密码增加update功能

This commit is contained in:
飘辰
2021-06-09 16:13:30 +08:00
parent 68f73c9e64
commit b3a191bf90
2 changed files with 42 additions and 0 deletions

View File

@@ -218,6 +218,34 @@ public class SymmetricCrypto implements Serializable {
}
}
/**
* 更新数据,分组加密中间结果可以当作随机数
*
* @param data 被加密的bytes
* @return update之后的bytes
*/
public byte[] update(byte[] data) {
lock.lock();
try {
final Cipher cipher = initCipher(Cipher.ENCRYPT_MODE);
return cipher.update(paddingDataWithZero(data, cipher.getBlockSize()));
} catch (Exception e) {
throw new CryptoException(e);
} finally {
lock.unlock();
}
}
/**
* 更新数据,分组加密中间结果可以当作随机数
*
* @param data 被加密的bytes
* @return update之后的hex数据
*/
public String updateHex(byte[] data) {
return HexUtil.encodeHexStr(update(data));
}
/**
* 加密,针对大数据量,结束后不关闭流
*