⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cbcblockcipher.java

📁 进行与数字证书相关开发必须的java源码
💻 JAVA
字号:
// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 
// Source File Name:   CBCBlockCipher.java

package jit.crypto.modes;

import jit.crypto.*;
import jit.crypto.params.ParametersWithIV;

public class CBCBlockCipher
    implements BlockCipher
{

    private byte IV[];
    private byte cbcV[];
    private byte cbcNextV[];
    private int blockSize;
    private BlockCipher cipher;
    private boolean encrypting;

    public CBCBlockCipher(BlockCipher cipher)
    {
        this.cipher = null;
        this.cipher = cipher;
        blockSize = cipher.getBlockSize();
        IV = new byte[blockSize];
        cbcV = new byte[blockSize];
        cbcNextV = new byte[blockSize];
    }

    public BlockCipher getUnderlyingCipher()
    {
        return cipher;
    }

    public void init(boolean encrypting, CipherParameters params)
        throws IllegalArgumentException
    {
        this.encrypting = encrypting;
        if(params instanceof ParametersWithIV)
        {
            ParametersWithIV ivParam = (ParametersWithIV)params;
            byte iv[] = ivParam.getIV();
            if(iv.length != blockSize)
                throw new IllegalArgumentException("initialisation vector must be the same length as block size");
            System.arraycopy(iv, 0, IV, 0, iv.length);
            reset();
            cipher.init(encrypting, ivParam.getParameters());
        } else
        {
            reset();
            cipher.init(encrypting, params);
        }
    }

    public String getAlgorithmName()
    {
        return String.valueOf(String.valueOf(cipher.getAlgorithmName())).concat("/CBC");
    }

    public int getBlockSize()
    {
        return cipher.getBlockSize();
    }

    public int processBlock(byte in[], int inOff, byte out[], int outOff)
        throws IllegalStateException, DataLengthException
    {
        return encrypting ? encryptBlock(in, inOff, out, outOff) : decryptBlock(in, inOff, out, outOff);
    }

    public void reset()
    {
        System.arraycopy(IV, 0, cbcV, 0, IV.length);
        cipher.reset();
    }

    private int encryptBlock(byte in[], int inOff, byte out[], int outOff)
        throws IllegalStateException, DataLengthException
    {
        if(inOff + blockSize > in.length)
            throw new DataLengthException("input buffer too short");
        for(int i = 0; i < blockSize; i++)
            cbcV[i] ^= in[inOff + i];

        int length = cipher.processBlock(cbcV, 0, out, outOff);
        System.arraycopy(out, outOff, cbcV, 0, cbcV.length);
        return length;
    }

    private int decryptBlock(byte in[], int inOff, byte out[], int outOff)
        throws IllegalStateException, DataLengthException
    {
        if(inOff + blockSize > in.length)
            throw new DataLengthException("input buffer too short");
        System.arraycopy(in, inOff, cbcNextV, 0, blockSize);
        int length = cipher.processBlock(in, inOff, out, outOff);
        for(int i = 0; i < blockSize; i++)
            out[outOff + i] ^= cbcV[i];

        byte tmp[] = cbcV;
        cbcV = cbcNextV;
        cbcNextV = tmp;
        return length;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -