1
package org.bouncycastle.crypto.paddings;
3
import java.security.SecureRandom;
5
import org.bouncycastle.crypto.InvalidCipherTextException;
8
* A padder that adds X9.23 padding to a block - if a SecureRandom is
9
* passed in random padding is assumed, otherwise padding with zeros is used.
11
public class X923Padding
12
implements BlockCipherPadding
14
SecureRandom random = null;
17
* Initialise the padder.
19
* @param random a SecureRandom if one is available.
21
public void init(SecureRandom random)
22
throws IllegalArgumentException
28
* Return the name of the algorithm the padder implements.
30
* @return the name of the algorithm the padder implements.
32
public String getPaddingName()
38
* add the pad bytes to the passed in block, returning the
39
* number of bytes added.
41
public int addPadding(
45
byte code = (byte)(in.length - inOff);
47
while (inOff < in.length - 1)
55
in[inOff] = (byte)random.nextInt();
66
* return the number of pad bytes present in the block.
68
public int padCount(byte[] in)
69
throws InvalidCipherTextException
71
int count = in[in.length - 1] & 0xff;
73
if (count > in.length)
75
throw new InvalidCipherTextException("pad block corrupted");