📄 paddedbufferedblockcipher.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: PaddedBufferedBlockCipher.java
package jit.crypto.paddings;
import jit.crypto.*;
import jit.crypto.params.ParametersWithRandom;
// Referenced classes of package jit.crypto.paddings:
// PKCS7Padding, BlockCipherPadding
public class PaddedBufferedBlockCipher extends BufferedBlockCipher
{
BlockCipherPadding padding;
public PaddedBufferedBlockCipher(BlockCipher cipher, BlockCipherPadding padding)
{
this.cipher = cipher;
this.padding = padding;
buf = new byte[cipher.getBlockSize()];
bufOff = 0;
}
public PaddedBufferedBlockCipher(BlockCipher cipher)
{
this(cipher, ((BlockCipherPadding) (new PKCS7Padding())));
}
public void init(boolean forEncryption, CipherParameters params)
throws IllegalArgumentException
{
this.forEncryption = forEncryption;
reset();
if(params instanceof ParametersWithRandom)
{
ParametersWithRandom p = (ParametersWithRandom)params;
padding.init(p.getRandom());
cipher.init(forEncryption, p.getParameters());
} else
{
padding.init(null);
cipher.init(forEncryption, params);
}
}
public int getOutputSize(int len)
{
int total = len + bufOff;
int leftOver = total % buf.length;
if(leftOver == 0)
{
if(forEncryption)
return total + buf.length;
else
return total;
} else
{
return (total - leftOver) + buf.length;
}
}
public int getUpdateOutputSize(int len)
{
int total = len + bufOff;
int leftOver = total % buf.length;
if(leftOver == 0)
return total - buf.length;
else
return total - leftOver;
}
public int processByte(byte in, byte out[], int outOff)
throws IllegalStateException, DataLengthException
{
int resultLen = 0;
if(bufOff == buf.length)
{
resultLen = cipher.processBlock(buf, 0, out, outOff);
bufOff = 0;
}
buf[bufOff++] = in;
return resultLen;
}
public int processBytes(byte in[], int inOff, int len, byte out[], int outOff)
throws IllegalStateException, DataLengthException
{
if(len < 0)
throw new IllegalArgumentException("Can't have a negative input length!");
int blockSize = getBlockSize();
int length = getUpdateOutputSize(len);
if(length > 0 && outOff + length > out.length)
throw new DataLengthException("output buffer too short");
int resultLen = 0;
int gapLen = buf.length - bufOff;
if(len > gapLen)
{
System.arraycopy(in, inOff, buf, bufOff, gapLen);
resultLen += cipher.processBlock(buf, 0, out, outOff);
bufOff = 0;
len -= gapLen;
for(inOff += gapLen; len > buf.length; inOff += blockSize)
{
resultLen += cipher.processBlock(in, inOff, out, outOff + resultLen);
len -= blockSize;
}
}
System.arraycopy(in, inOff, buf, bufOff, len);
bufOff += len;
return resultLen;
}
public int doFinal(byte out[], int outOff)
throws InvalidCipherTextException, IllegalStateException, DataLengthException
{
int blockSize = cipher.getBlockSize();
int resultLen = 0;
if(forEncryption)
{
if(bufOff == blockSize)
{
if(outOff + 2 * blockSize > out.length)
{
reset();
throw new DataLengthException("output buffer too short");
}
resultLen = cipher.processBlock(buf, 0, out, outOff);
bufOff = 0;
}
padding.addPadding(buf, bufOff);
resultLen += cipher.processBlock(buf, 0, out, outOff + resultLen);
reset();
} else
{
if(bufOff == blockSize)
{
resultLen = cipher.processBlock(buf, 0, buf, 0);
bufOff = 0;
} else
{
reset();
throw new DataLengthException("last block incomplete in decryption");
}
try
{
resultLen -= padding.padCount(buf);
System.arraycopy(buf, 0, out, outOff, resultLen);
}
finally
{
reset();
}
}
return resultLen;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -