java.lang.Object
org.miaixz.bus.crypto.cipher.BCCipher
- All Implemented Interfaces:
org.miaixz.bus.core.lang.Wrapper<Object>,org.miaixz.bus.core.Provider,Cipher
基于BouncyCastle库封装的加密解密实现,包装包括:
BufferedBlockCipherBlockCipherStreamCipherAEADBlockCipher
- Since:
- Java 17+
- Author:
- Kimi Liu
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBouncyCastle库的CipherParameters封装Nested classes/interfaces inherited from interface org.miaixz.bus.crypto.Cipher
Cipher.Parameters -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintdoFinal(byte[] out, int outOff) 处理最后一块数据 当Cipher.process(byte[], int, int, byte[], int)处理完数据后非完整块数据,此方法用于处理块中剩余的bytes 如加密数据要求128bit,即16byes的整数,单数处理数据后为15bytes,此时根据padding方式不同,可填充剩余1byte为指定值(如填充0) 当对数据进行分段加密时,需要首先多次执行process方法,在最后一块数据处理完后执行此方法。获取算法名称int获取块大小,当为Stream方式加密时返回0intgetOutputSize(int len) 返回输出缓冲区为了保存下一个update或doFinal操作的结果所需的长度(以字节为单位) 下一个update或doFinal调用的实际输出长度可能小于此方法返回的长度。getRaw()voidinit(org.miaixz.bus.core.lang.Algorithm.Type mode, Cipher.Parameters parameters) 初始化模式和参数intprocess(byte[] in, int inOff, int len, byte[] out, int outOff) 执行运算,可以是加密运算或解密运算 此方法主要处理一块数据,一块数据处理完毕后,应调用Cipher.doFinal(byte[], int)处理padding等剩余数据。Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.miaixz.bus.crypto.Cipher
processFinal, processFinalMethods inherited from interface org.miaixz.bus.core.lang.Wrapper
type
-
Constructor Details
-
BCCipher
public BCCipher(org.bouncycastle.crypto.BufferedBlockCipher bufferedBlockCipher) 构造- Parameters:
bufferedBlockCipher-BufferedBlockCipher
-
BCCipher
public BCCipher(org.bouncycastle.crypto.BlockCipher blockCipher) 构造- Parameters:
blockCipher-BlockCipher
-
BCCipher
public BCCipher(org.bouncycastle.crypto.modes.AEADBlockCipher aeadBlockCipher) 构造- Parameters:
aeadBlockCipher-AEADBlockCipher
-
BCCipher
public BCCipher(org.bouncycastle.crypto.StreamCipher streamCipher) 构造- Parameters:
streamCipher-StreamCipher
-
-
Method Details
-
getRaw
- Specified by:
getRawin interfaceorg.miaixz.bus.core.lang.Wrapper<Object>
-
getAlgorithm
Description copied from interface:Cipher获取算法名称- Specified by:
getAlgorithmin interfaceCipher- Returns:
- 算法名称
-
getBlockSize
public int getBlockSize()Description copied from interface:Cipher获取块大小,当为Stream方式加密时返回0- Specified by:
getBlockSizein interfaceCipher- Returns:
- 块大小,-1表示非块加密
-
init
Description copied from interface:Cipher初始化模式和参数 -
getOutputSize
public int getOutputSize(int len) Description copied from interface:Cipher返回输出缓冲区为了保存下一个update或doFinal操作的结果所需的长度(以字节为单位) 下一个update或doFinal调用的实际输出长度可能小于此方法返回的长度。 一般为块大小对应的输出大小- Specified by:
getOutputSizein interfaceCipher- Parameters:
len- 输入长度- Returns:
- 输出长度,-1表示非块加密
-
process
public int process(byte[] in, int inOff, int len, byte[] out, int outOff) Description copied from interface:Cipher执行运算,可以是加密运算或解密运算 此方法主要处理一块数据,一块数据处理完毕后,应调用Cipher.doFinal(byte[], int)处理padding等剩余数据。 -
doFinal
public int doFinal(byte[] out, int outOff) Description copied from interface:Cipher处理最后一块数据 当Cipher.process(byte[], int, int, byte[], int)处理完数据后非完整块数据,此方法用于处理块中剩余的bytes 如加密数据要求128bit,即16byes的整数,单数处理数据后为15bytes,此时根据padding方式不同,可填充剩余1byte为指定值(如填充0) 当对数据进行分段加密时,需要首先多次执行process方法,在最后一块数据处理完后执行此方法。
-