protected byte[] engineUpdate( byte[] input, int inputOffset, int inputLen) { int length = cipher.getUpdateOutputSize(inputLen); if (length > 0) { byte[] out = new byte[length]; int len = cipher.processBytes(input, inputOffset, inputLen, out, 0); if (len == 0) { return null; } else if (len != out.length) { byte[] tmp = new byte[len]; System.arraycopy(out, 0, tmp, 0, len); return tmp; } return out; } cipher.processBytes(input, inputOffset, inputLen, null, 0); return null; }
protected int engineUpdate( byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset) throws ShortBufferException { if (outputOffset + cipher.getUpdateOutputSize(inputLen) > output.length) { throw new ShortBufferException("output buffer too short for input."); } try { return cipher.processBytes(input, inputOffset, inputLen, output, outputOffset); } catch (DataLengthException e) { // should never occur throw new IllegalStateException(e.toString()); } }
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()); } if (len == tmp.length) { return tmp; } byte[] out = new byte[len]; System.arraycopy(tmp, 0, out, 0, len); return out; }
protected int engineDoFinal( byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset) throws IllegalBlockSizeException, BadPaddingException, ShortBufferException { int len = 0; if (outputOffset + engineGetOutputSize(inputLen) > output.length) { throw new ShortBufferException("output buffer too short for input."); } try { if (inputLen != 0) { len = cipher.processBytes(input, inputOffset, inputLen, output, outputOffset); } return (len + cipher.doFinal(output, outputOffset + len)); } catch (OutputLengthException e) { throw new IllegalBlockSizeException(e.getMessage()); } catch (DataLengthException e) { throw new IllegalBlockSizeException(e.getMessage()); } }