42 lines
1.4 KiB
Java
42 lines
1.4 KiB
Java
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 PKCS7Padding implements BlockCipherPadding {
|
|
@Override // org.bouncycastle.crypto.paddings.BlockCipherPadding
|
|
public void init(SecureRandom secureRandom) throws IllegalArgumentException {
|
|
}
|
|
|
|
@Override // org.bouncycastle.crypto.paddings.BlockCipherPadding
|
|
public int padCount(byte[] bArr) throws InvalidCipherTextException {
|
|
int i = bArr[bArr.length - 1] & UnsignedBytes.MAX_VALUE;
|
|
byte b = (byte) i;
|
|
boolean z = (i > bArr.length) | (i == 0);
|
|
for (int i2 = 0; i2 < bArr.length; i2++) {
|
|
z |= (bArr.length - i2 <= i) & (bArr[i2] != b);
|
|
}
|
|
if (z) {
|
|
throw new InvalidCipherTextException("pad block corrupted");
|
|
}
|
|
return i;
|
|
}
|
|
|
|
@Override // org.bouncycastle.crypto.paddings.BlockCipherPadding
|
|
public String getPaddingName() {
|
|
return "PKCS7";
|
|
}
|
|
|
|
@Override // org.bouncycastle.crypto.paddings.BlockCipherPadding
|
|
public int addPadding(byte[] bArr, int i) {
|
|
byte length = (byte) (bArr.length - i);
|
|
while (i < bArr.length) {
|
|
bArr[i] = length;
|
|
i++;
|
|
}
|
|
return length;
|
|
}
|
|
}
|