what-the-bank/sources/org/bouncycastle/crypto/paddings/ISO10126d2Padding.java

44 lines
1.4 KiB
Java
Raw Normal View History

2024-07-27 18:17:47 +07:00
package org.bouncycastle.crypto.paddings;
import com.google.common.primitives.UnsignedBytes;
import java.security.SecureRandom;
import org.bouncycastle.crypto.InvalidCipherTextException;
/* loaded from: classes6.dex */
public class ISO10126d2Padding implements BlockCipherPadding {
SecureRandom random;
@Override // org.bouncycastle.crypto.paddings.BlockCipherPadding
public int padCount(byte[] bArr) throws InvalidCipherTextException {
int i = bArr[bArr.length - 1] & UnsignedBytes.MAX_VALUE;
if (i <= bArr.length) {
return i;
}
throw new InvalidCipherTextException("pad block corrupted");
}
@Override // org.bouncycastle.crypto.paddings.BlockCipherPadding
public void init(SecureRandom secureRandom) throws IllegalArgumentException {
if (secureRandom == null) {
secureRandom = new SecureRandom();
}
this.random = secureRandom;
}
@Override // org.bouncycastle.crypto.paddings.BlockCipherPadding
public String getPaddingName() {
return "ISO10126-2";
}
@Override // org.bouncycastle.crypto.paddings.BlockCipherPadding
public int addPadding(byte[] bArr, int i) {
byte length = (byte) (bArr.length - i);
while (i < bArr.length - 1) {
bArr[i] = (byte) this.random.nextInt();
i++;
}
bArr[i] = length;
return length;
}
}