This commit is contained in:
Looly 2024-08-15 10:41:20 +08:00
parent a07317fee4
commit 3bb4cb3012
2 changed files with 38 additions and 1 deletions

View File

@ -19,7 +19,11 @@ package org.dromara.hutool.crypto;
import java.util.Arrays;
/**
* 密码接口提供统一的API用于兼容和统一JCE和BouncyCastle等库的操作
* 密码接口提供统一的API用于兼容和统一JCE和BouncyCastle等库的操作<br>
* <ul>
* <li>process和doFinal组合使用用于分块加密或解密</li>
* <li>processFinal默认处理并输出小于块的数据或一次性数据</li>
* </ul>
*
* @author Looly
* @since 6.0.0

View File

@ -112,6 +112,38 @@ public class JceCipher extends SimpleWrapper<javax.crypto.Cipher> implements Cip
}
}
// region ----- process
/**
* 继续多部分加密或解密操作取决于此密码的初始化方式处理另一个数据部分
* 第一inputLen字节在input缓冲区中从inputOffset以下被处理并且结果被存储在output缓冲器
*
* @param in 输入缓冲区
* @param inOff 输入开始的 input中的偏移量
* @param len 输入长度
* @return 带有结果的新缓冲区如果底层密码是块密码且输入数据太短而不能产生新块则返回null
*/
public byte[] process(final byte[] in, final int inOff, final int len) {
return this.raw.update(in, inOff, len);
}
/**
* 继续多部分加密或解密操作取决于此密码的初始化方式处理另一个数据部分
* 第一inputLen字节在input缓冲区中从inputOffset以下被处理并且结果被存储在output缓冲器
*
* @param in 输入缓冲区
* @param inOff 输入开始的 input中的偏移量
* @param len 输入长度
* @param out 结果的缓冲区
* @return 存储在 output的字节数
*/
public int process(final byte[] in, final int inOff, final int len, final byte[] out) {
try {
return this.raw.update(in, inOff, len, out);
} catch (final ShortBufferException e) {
throw new CryptoException(e);
}
}
@Override
public int process(final byte[] in, final int inOff, final int len, final byte[] out, final int outOff) {
try {
@ -120,6 +152,7 @@ public class JceCipher extends SimpleWrapper<javax.crypto.Cipher> implements Cip
throw new CryptoException(e);
}
}
// endregion
@Override
public int doFinal(final byte[] out, final int outOff) {