List of usage examples for org.bouncycastle.crypto DataLengthException DataLengthException
public DataLengthException(String message)
From source file:com.DSC.crypto.ISAACRandomGenerator.java
License:Open Source License
/** * Initialize the ISAAC random generator with an initial seed value. The seed * value must be specified, future versions will enforce a minimum level of * entropy, week seeds will throw exceptions! * // ww w. j a v a 2 s . c om * @param seed The seed value, must be specified * * @throws DataLengthException if the seed is not specified or has weak entropy */ public void init(byte[] seed) throws DataLengthException { /* * TODO Add a check to throw an exception if the level of entropy does not * meet minimum requirements */ if (seed.length == 0) { throw new DataLengthException("Seed cannot be empty, you must specify a high entropy seed!"); } this.seed = seed; // Initialize the stream cipher engine engine.init(true, new KeyParameter(seed)); }
From source file:com.DSC.crypto.ISAACRandomGenerator.java
License:Open Source License
public void addSeedMaterial(byte[] seed) throws DataLengthException { /*/*from www. jav a2 s. c o m*/ * TODO Add a check to throw an exception if the level of entropy does not * meet minimum requirements */ if (seed.length == 0) { throw new DataLengthException("Seed cannot be empty, you must specify a high entropy seed!"); } /* * Resize the current array of bytes for the seed and add the additional seed data * to the current seed value, then re-initialize the stream cipher with the new * seed data */ byte[] newSeed = new byte[this.seed.length + seed.length]; System.arraycopy(this.seed, 0, newSeed, 0, this.seed.length); System.arraycopy(seed, 0, newSeed, this.seed.length, seed.length); this.seed = newSeed; this.engine.reset(); this.engine.init(true, new KeyParameter(newSeed)); }
From source file:com.DSC.crypto.ISAACRandomGenerator.java
License:Open Source License
public void addSeedMaterial(long seed) throws DataLengthException { /*/*from w w w . ja va 2 s . c om*/ * TODO Add a check to throw an exception if the level of entropy does not * meet minimum requirements */ if (seed == 0) { throw new DataLengthException("Seed cannot be zero, you must specify a high entropy seed!"); } /* * Convert the seed from long to bytes and add the additional seed data * to the current seed value, then re-initialize the stream cipher with the * new seed data */ byte[] convSeed = new byte[Long.SIZE / 8]; // Long is 8 bytes byte[] newSeed = new byte[this.seed.length + convSeed.length]; ByteBuffer buf = ByteBuffer.wrap(convSeed); buf.putLong(seed); System.arraycopy(this.seed, 0, newSeed, 0, this.seed.length); System.arraycopy(convSeed, 0, newSeed, this.seed.length, convSeed.length); this.seed = newSeed; this.engine.reset(); this.engine.init(true, new KeyParameter(newSeed)); }
From source file:com.github.horrorho.inflatabledonkey.crypto.xts.XTSAESCipher.java
License:Open Source License
int process(byte[] in, int inOff, int length, byte[] out, int outOff) throws DataLengthException, IllegalStateException { if (length < blockSize) { throw new DataLengthException("data unit size too small: " + length); }/*from ww w .j a v a 2s .c om*/ if (inOff + length > in.length) { throw new DataLengthException("input buffer too small for data unit size: " + length); } if (outOff + length > out.length) { throw new DataLengthException("output buffer too small for data unit size: " + length); } int to = length % blockSize == 0 ? length : length - (blockSize * 2); int i; for (i = 0; i < to; i += blockSize) { core.processBlock(in, inOff + i, out, outOff + i); } if (length > i) { core.processPartial(in, inOff + i, out, outOff + i, length - i); } return length; }
From source file:com.github.horrorho.inflatabledonkey.crypto.xts.XTSCore.java
License:Open Source License
int processPartial(byte[] in, int inOff, byte[] out, int outOff, int length) { if (length <= BLOCK_SIZE) { throw new DataLengthException("input buffer too small/ missing last two blocks: " + length); }/*from ww w .j a v a 2s . c o m*/ if (length >= BLOCK_SIZE * 2) { throw new DataLengthException("input buffer too large/ non-partial final block: " + length); } byte[] tweakA = tweak.value(); byte[] tweakB = tweak.next().value(); return forEncryption ? XTSCore.this.doProcessPartial(in, inOff, out, outOff, length, tweakA, tweakB) : XTSCore.this.doProcessPartial(in, inOff, out, outOff, length, tweakB, tweakA); }
From source file:com.joyent.http.signature.crypto.MantaNativeRSACoreEngine.java
License:Apache License
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."); }/* w w w. ja va 2 s.co m*/ 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; }
From source file:com.thoughtworks.go.config.EnvironmentVariableConfigTest.java
License:Apache License
@Test public void shouldErrorOutOnValidateWhenEncryptedValueIsForceChanged() throws InvalidCipherTextException { String plainText = "secure_value"; String cipherText = "cipherText"; when(goCipher.encrypt(plainText)).thenReturn(cipherText); when(goCipher.decrypt(cipherText))// www . jav a 2 s . com .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.")); }
From source file:eg.nileu.cis.nilestore.cryptography.AESCipher.java
License:Open Source License
/** * Process bytes.//from ww w.j ava 2 s . c o m * * @param in * the in * @param inOff * the in off * @param len * the len * @param out * the out * @param outOff * the out off * @return the int * @throws IllegalArgumentException * the illegal argument exception * @throws DataLengthException * the data length exception */ public int processBytes(byte[] in, int inOff, int len, byte[] out, int outOff) throws IllegalArgumentException, DataLengthException { if (len < 0) { throw new IllegalArgumentException("Can't have a negative input length!"); } if (len > 0) { if ((outOff + len) > out.length) { throw new DataLengthException("output buffer too short"); } } int padding = 0; int _len = len; int _inoff = inOff; int _outoff = outOff; if (prev_padding != 0) { int prefix_length = blockSize - prev_padding; _inoff += prefix_length; _outoff += prefix_length; _len -= prefix_length; byte[] padded_prefix = new byte[blockSize]; System.arraycopy(in, inOff, padded_prefix, prev_padding, prefix_length); cipher.Countermm(); cipher.processBlock(padded_prefix, 0, padded_prefix, 0); System.arraycopy(padded_prefix, prev_padding, out, outOff, prefix_length); } padding = _len % blockSize; if (padding == 0) { processBlocks(in, _inoff, _len, out, _outoff); } else { int new_len = _len - padding; processBlocks(in, _inoff, new_len, out, _outoff); _outoff += new_len; _inoff += new_len; byte[] padded_suffix = new byte[blockSize]; System.arraycopy(in, _inoff, padded_suffix, 0, padding); cipher.processBlock(padded_suffix, 0, padded_suffix, 0); System.arraycopy(padded_suffix, 0, out, _outoff, padding); } prev_padding = padding; return len; }
From source file:eg.nileu.cis.nilestore.cryptography.AESCipher.java
License:Open Source License
/** * Process blocks.//from w w w . j a va 2 s . c om * * @param in * the in * @param inOff * the in off * @param len * the len * @param out * the out * @param outOff * the out off */ private void processBlocks(byte[] in, int inOff, int len, byte[] out, int outOff) { int resultLen = 0; if (len % blockSize != 0) { throw new DataLengthException("input array length should be multiple of the blocksize"); } int num_blocks = len / blockSize; while (num_blocks > 0) { resultLen += cipher.processBlock(in, inOff, out, outOff + resultLen); len -= blockSize; inOff += blockSize; num_blocks--; } }
From source file:org.cryptomator.siv.JceAesBlockCipher.java
License:Open Source License
@Override public int processBlock(byte[] in, int inOff, byte[] out, int outOff) throws DataLengthException, IllegalStateException { if (in.length - inOff < getBlockSize()) { throw new DataLengthException("Insufficient data in 'in'."); }/* w w w. j a v a2 s.c om*/ try { return cipher.update(in, inOff, getBlockSize(), out, outOff); } catch (ShortBufferException e) { throw new DataLengthException("Insufficient space in 'out'."); } }