List of usage examples for org.bouncycastle.crypto DataLengthException DataLengthException
public DataLengthException()
From source file:action.ShowTimeSeriesWithForecastAction.java
License:Open Source License
/** * Metoda obslugujaca zdarzenie, odpowiedzialna za inicjalizacje algorytmu genetycznego *//* w w w . java2 s .c om*/ public void actionPerformed(ActionEvent e) { try { if (window.getSliderSelekcji().getValue() + window.getSliderKrzyzowania().getValue() + window.getSliderMutacji().getValue() != 100) throw new ParseException( "Please insert correct data for Selection, Crossing and Mutation. The sum of the three has to equal 100%", 0); TimeSeries timeSeries = window.getCurrentTimeSeries(); if (timeSeries == null || timeSeries.isEmpty()) throw new DataLengthException(); SlidingTimeWindow slidingTimeWindow = new SlidingTimeWindow( this.parseToWindowForm(window.getTimeWindowField().getText())); if (window.getRdBtnStochastic().isSelected()) GASettings.getInstance() .setSelectionMethod(SelectionMethod.STOCHASTIC_UNIVERSAL_SAMPLING_SELECTION); if (window.getRdbtnArmaForecast().isSelected()) GASettings.getInstance().setForecastMethod(ForecastMethod.ARMA_FORECAST); GASettings.getInstance().setConcurrent(true); ApplicationContext context = new AnnotationConfigApplicationContext(ForecastConfig.class); AbstractForecast forecast = (AbstractForecast) context.getBean("forecast"); forecast.initializeGeneticAlgorithm((TimeSeries) timeSeries.clone(), (Integer) window.getPopulSizeField().getValue(), slidingTimeWindow, (Integer) window.getIterNumberField().getValue(), (double) window.getSliderProbOfCross().getValue() / 100, (double) window.getSliderProbOfMutat().getValue() / 100, (double) window.getSliderSelekcji().getValue() / 100, (double) window.getSliderKrzyzowania().getValue() / 100, (double) window.getSliderMutacji().getValue() / 100); forecast.initializeForecast((Integer) window.getPeriodOfPredField().getValue()); forecast.addObserver(new GAChartObserver(window.getFitnessChart(), window.getTimeSeriesChartWithForecast(), (Integer) window.getPeriodOfPredField().getValue())); forecast.addObserver(new GAStatisticObserver(window.getForecast(), (Integer) window.getPeriodOfPredField().getValue())); forecast.execute(); window.getTabbedPane().setSelectedIndex(3); } catch (CloneNotSupportedException e1) { e1.printStackTrace(); } catch (DataLengthException de) { JOptionPane.showMessageDialog(window, "Current data is not set or empty", "Error", JOptionPane.ERROR_MESSAGE); } catch (ParseException pe) { JOptionPane.showMessageDialog(window, pe.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } catch (Exception exc) { JOptionPane.showMessageDialog(window, "Wrong data", "Error", JOptionPane.ERROR_MESSAGE); } }
From source file:org.jitsi.impl.neomedia.transform.srtp.BlockCipherAdapter.java
License:LGPL
/** * {@inheritDoc}// ww w . ja v a 2s.c o m */ @Override public int processBlock(byte[] in, int inOff, byte[] out, int outOff) throws DataLengthException, IllegalStateException { try { return cipher.update(in, inOff, getBlockSize(), out, outOff); } catch (ShortBufferException sbe) { logger.error(sbe, sbe); DataLengthException dle = new DataLengthException(); dle.initCause(sbe); throw dle; } }
From source file:org.panbox.core.crypto.io.AESGCMRandomAccessFileHW.java
License:Open Source License
@Override protected void initCiphers() throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, RandomDataGenerationException, InvalidAlgorithmParameterException, NoSuchProviderException { super.initCiphers(); // TODO: This following code mixes the SunJCE AES blockcipher // implementation with Bouncycastle's GCMBlockCipher to improve // performance due to SunJCE's AES NI support. Replace this with // "native" BC code, as soon as they introduce AES NI support // themselves. For more information see // http://bouncy-castle.1462172.n4.nabble.com/Using-BC-AES-GCM-for-S3-td4657050.html this.gcmEngine = new GCMBlockCipher(new BlockCipher() { Cipher aes = Cipher.getInstance("AES/ECB/NoPadding", KeyConstants.PROV_SunJCE); public void reset() { }/*from ww w . j a v a2 s .c o m*/ public int processBlock(byte[] in, int inOff, byte[] out, int outOff) throws DataLengthException, IllegalStateException { try { aes.update(in, outOff, getBlockSize(), out, outOff); } catch (ShortBufferException e) { throw new DataLengthException(); } return getBlockSize(); } public void init(boolean forEncryption, CipherParameters params) throws IllegalArgumentException { KeyParameter kp = (KeyParameter) params; SecretKeySpec key = new SecretKeySpec(kp.getKey(), "AES"); try { aes.init(forEncryption ? Cipher.ENCRYPT_MODE : Cipher.DECRYPT_MODE, key); } catch (InvalidKeyException e) { throw new IllegalArgumentException(e); } } public int getBlockSize() { return aes.getBlockSize(); } public String getAlgorithmName() { return aes.getAlgorithm(); } }); }