use of org.bouncycastle.crypto.DataLengthException in project robovm by robovm.
the class RSACoreEngine method convertInput.
public BigInteger convertInput(byte[] in, int inOff, int inLen) {
if (inLen > (getInputBlockSize() + 1)) {
throw new DataLengthException("input too large for RSA cipher.");
} else if (inLen == (getInputBlockSize() + 1) && !forEncryption) {
throw new DataLengthException("input too large for RSA cipher.");
}
byte[] block;
if (inOff != 0 || inLen != in.length) {
block = new byte[inLen];
System.arraycopy(in, inOff, block, 0, inLen);
} else {
block = in;
}
BigInteger res = new BigInteger(1, block);
if (res.compareTo(key.getModulus()) >= 0) {
throw new DataLengthException("input too large for RSA cipher.");
}
return res;
}
use of org.bouncycastle.crypto.DataLengthException in project XobotOS by xamarin.
the class RSACoreEngine method convertInput.
public BigInteger convertInput(byte[] in, int inOff, int inLen) {
if (inLen > (getInputBlockSize() + 1)) {
throw new DataLengthException("input too large for RSA cipher.");
} else if (inLen == (getInputBlockSize() + 1) && !forEncryption) {
throw new DataLengthException("input too large for RSA cipher.");
}
byte[] block;
if (inOff != 0 || inLen != in.length) {
block = new byte[inLen];
System.arraycopy(in, inOff, block, 0, inLen);
} else {
block = in;
}
BigInteger res = new BigInteger(1, block);
if (res.compareTo(key.getModulus()) >= 0) {
throw new DataLengthException("input too large for RSA cipher.");
}
return res;
}
use of org.bouncycastle.crypto.DataLengthException in project XobotOS by xamarin.
the class JCEBlockCipher method engineDoFinal.
protected int engineDoFinal(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset) throws IllegalBlockSizeException, BadPaddingException, ShortBufferException {
// BEGIN android-note
// added ShortBufferException to the throws statement
// END android-note
int len = 0;
// BEGIN android-added
int outputLen = cipher.getOutputSize(inputLen);
if (outputLen + outputOffset > output.length) {
throw new ShortBufferException("need at least " + outputLen + " bytes");
}
if (inputLen != 0) {
len = cipher.processBytes(input, inputOffset, inputLen, output, outputOffset);
}
try {
return (len + cipher.doFinal(output, outputOffset + len));
} catch (DataLengthException e) {
throw new IllegalBlockSizeException(e.getMessage());
} catch (InvalidCipherTextException e) {
throw new BadPaddingException(e.getMessage());
}
}
use of org.bouncycastle.crypto.DataLengthException in project gocd by gocd.
the class EnvironmentVariableConfigTest method shouldErrorOutOnValidateWhenEncryptedValueIsForceChanged.
@Test
public void shouldErrorOutOnValidateWhenEncryptedValueIsForceChanged() throws InvalidCipherTextException {
String plainText = "secure_value";
String cipherText = "cipherText";
when(goCipher.encrypt(plainText)).thenReturn(cipherText);
when(goCipher.decrypt(cipherText)).thenThrow(new DataLengthException("last block incomplete in decryption"));
EnvironmentVariableConfig environmentVariableConfig = new EnvironmentVariableConfig(goCipher, "secure_key", plainText, true);
environmentVariableConfig.validate(null);
ConfigErrors error = environmentVariableConfig.errors();
assertThat(error.isEmpty(), is(false));
assertThat(error.on(EnvironmentVariableConfig.VALUE), is("Encrypted value for variable named 'secure_key' is invalid. This usually happens when the cipher text is modified to have an invalid value."));
}
use of org.bouncycastle.crypto.DataLengthException in project robovm by robovm.
the class BaseBlockCipher method engineDoFinal.
protected byte[] engineDoFinal(byte[] input, int inputOffset, int inputLen) throws IllegalBlockSizeException, BadPaddingException {
int len = 0;
byte[] tmp = new byte[engineGetOutputSize(inputLen)];
if (inputLen != 0) {
len = cipher.processBytes(input, inputOffset, inputLen, tmp, 0);
}
try {
len += cipher.doFinal(tmp, len);
} catch (DataLengthException e) {
throw new IllegalBlockSizeException(e.getMessage());
} catch (InvalidCipherTextException e) {
throw new BadPaddingException(e.getMessage());
}
if (len == tmp.length) {
return tmp;
}
byte[] out = new byte[len];
System.arraycopy(tmp, 0, out, 0, len);
return out;
}
Aggregations