Module bus.crypto

Class JceCipher

java.lang.Object
org.miaixz.bus.core.lang.wrapper.SimpleWrapper<Cipher>
org.miaixz.bus.crypto.cipher.JceCipher
All Implemented Interfaces:
org.miaixz.bus.core.lang.Wrapper<Cipher>, org.miaixz.bus.core.Provider, Cipher

public class JceCipher extends org.miaixz.bus.core.lang.wrapper.SimpleWrapper<Cipher> implements Cipher
提供Cipher的方法包装
Since:
Java 17+
Author:
Kimi Liu
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    JCE的AlgorithmParameterSpec 参数包装

    Nested classes/interfaces inherited from interface org.miaixz.bus.crypto.Cipher

    Cipher.Parameters
  • Field Summary

    Fields inherited from class org.miaixz.bus.core.lang.wrapper.SimpleWrapper

    raw
  • Constructor Summary

    Constructors
    Constructor
    Description
    JceCipher(String algorithm)
    构造
    JceCipher(Cipher cipher)
    构造
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    doFinal(byte[] out, int outOff)
    处理最后一块数据 当Cipher.process(byte[], int, int, byte[], int)处理完数据后非完整块数据,此方法用于处理块中剩余的bytes 如加密数据要求128bit,即16byes的整数,单数处理数据后为15bytes,此时根据padding方式不同,可填充剩余1byte为指定值(如填充0) 当对数据进行分段加密时,需要首先多次执行process方法,在最后一块数据处理完后执行此方法。
    获取算法名称
    int
    获取块大小,当为Stream方式加密时返回0
    byte[]
    返回新缓冲区中的初始化向量(IV) 这在创建随机IV的情况下,或在基于密码的加密或解密的上下文中是有用的,其中IV是从用户提供的密码导出的。
    int
    getOutputSize(int len)
    返回输出缓冲区为了保存下一个update或doFinal操作的结果所需的长度(以字节为单位) 下一个update或doFinal调用的实际输出长度可能小于此方法返回的长度。
    void
    init(int mode, JceCipher.JceParameters jceParameters)
    执行初始化参数操作
    void
    init(org.miaixz.bus.core.lang.Algorithm.Type mode, Cipher.Parameters parameters)
    初始化模式和参数
    byte[]
    process(byte[] in, int inOff, int len)
    继续多部分加密或解密操作(取决于此密码的初始化方式),处理另一个数据部分。
    int
    process(byte[] in, int inOff, int len, byte[] out)
    继续多部分加密或解密操作(取决于此密码的初始化方式),处理另一个数据部分。
    int
    process(byte[] in, int inOff, int len, byte[] out, int outOff)
    执行运算,可以是加密运算或解密运算 此方法主要处理一块数据,一块数据处理完毕后,应调用Cipher.doFinal(byte[], int)处理padding等剩余数据。
    byte[]
    processFinal(byte[] data, int inOffset, int inputLen)
    处理数据,并返回最终结果 此方法用于完整处理一块数据并返回。

    Methods inherited from class org.miaixz.bus.core.lang.wrapper.SimpleWrapper

    getRaw

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.miaixz.bus.crypto.Cipher

    processFinal

    Methods inherited from interface org.miaixz.bus.core.lang.Wrapper

    type
  • Constructor Details

  • Method Details

    • getAlgorithm

      public String getAlgorithm()
      Description copied from interface: Cipher
      获取算法名称
      Specified by:
      getAlgorithm in interface Cipher
      Returns:
      算法名称
    • getBlockSize

      public int getBlockSize()
      Description copied from interface: Cipher
      获取块大小,当为Stream方式加密时返回0
      Specified by:
      getBlockSize in interface Cipher
      Returns:
      块大小,-1表示非块加密
    • getOutputSize

      public int getOutputSize(int len)
      Description copied from interface: Cipher
      返回输出缓冲区为了保存下一个update或doFinal操作的结果所需的长度(以字节为单位) 下一个update或doFinal调用的实际输出长度可能小于此方法返回的长度。 一般为块大小对应的输出大小
      Specified by:
      getOutputSize in interface Cipher
      Parameters:
      len - 输入长度
      Returns:
      输出长度,-1表示非块加密
    • init

      public void init(org.miaixz.bus.core.lang.Algorithm.Type mode, Cipher.Parameters parameters)
      Description copied from interface: Cipher
      初始化模式和参数
      Specified by:
      init in interface Cipher
      Parameters:
      mode - 模式,如加密模式或解密模式
      parameters - Cipher所需参数,包括Key、Random、IV等信息
    • process

      public byte[] process(byte[] in, int inOff, int len)
      继续多部分加密或解密操作(取决于此密码的初始化方式),处理另一个数据部分。 第一inputLen字节在input缓冲区中,从inputOffset以下,被处理,并且结果被存储在output缓冲器。
      Parameters:
      in - 输入缓冲区
      inOff - 输入开始的 input中的偏移量
      len - 输入长度
      Returns:
      带有结果的新缓冲区,如果底层密码是块密码且输入数据太短而不能产生新块,则返回null。
    • process

      public int process(byte[] in, int inOff, int len, byte[] out)
      继续多部分加密或解密操作(取决于此密码的初始化方式),处理另一个数据部分。 第一inputLen字节在input缓冲区中,从inputOffset以下,被处理,并且结果被存储在output缓冲器。
      Parameters:
      in - 输入缓冲区
      inOff - 输入开始的 input中的偏移量
      len - 输入长度
      out - 结果的缓冲区
      Returns:
      存储在 output的字节数
    • getIV

      public byte[] getIV()
      返回新缓冲区中的初始化向量(IV) 这在创建随机IV的情况下,或在基于密码的加密或解密的上下文中是有用的,其中IV是从用户提供的密码导出的。
      Returns:
      新缓冲区中的初始化向量,如果基础算法不使用IV,或者尚未设置IV,则为null。
    • init

      public void init(int mode, JceCipher.JceParameters jceParameters) throws InvalidAlgorithmParameterException, InvalidKeyException
      执行初始化参数操作
      Parameters:
      mode - 模式
      jceParameters - JceCipher.JceParameters
      Throws:
      InvalidAlgorithmParameterException - 无效算法参数
      InvalidKeyException - 无效key
    • process

      public int process(byte[] in, int inOff, int len, byte[] out, int outOff)
      Description copied from interface: Cipher
      执行运算,可以是加密运算或解密运算 此方法主要处理一块数据,一块数据处理完毕后,应调用Cipher.doFinal(byte[], int)处理padding等剩余数据。
      Specified by:
      process in interface Cipher
      Parameters:
      in - 输入数据
      inOff - 输入数据开始位置
      len - 被处理数据长度
      out - 输出数据
      outOff - 输出数据开始位置
      Returns:
      处理长度
    • 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方法,在最后一块数据处理完后执行此方法。
      Specified by:
      doFinal in interface Cipher
      Parameters:
      out - 经过process执行过运算的结果数据
      outOff - 数据处理开始位置
      Returns:
      处理长度
    • processFinal

      public byte[] processFinal(byte[] data, int inOffset, int inputLen)
      Description copied from interface: Cipher
      处理数据,并返回最终结果 此方法用于完整处理一块数据并返回。
      Specified by:
      processFinal in interface Cipher
      Parameters:
      data - 输入数据
      inOffset - 输入开始的 input中的偏移量
      inputLen - 输入长度
      Returns:
      结果数据
      See Also: