throw new IOException(e.getMessage()); } catch (IllegalBlockSizeException e) { throw new IOException(e.getMessage());
throw new InvalidKeyException(e.getMessage()); } catch (BadPaddingException e) { throw new InvalidKeyException(e.getMessage());
throw new InvalidKeyException(e.getMessage()); } catch (BadPaddingException e) { throw new InvalidKeyException(e.getMessage());
throw new InvalidKeyException(e.getMessage()); } catch (BadPaddingException e) { throw new InvalidKeyException(e.getMessage());
throw new InvalidKeySpecException(e.getMessage()); } catch (BadPaddingException e) { throw new InvalidKeySpecException(e.getMessage());
@Override public byte[] getSignature() { try { return cipher.doFinal(); } catch (IllegalBlockSizeException ex) { throw new IllegalStateException("IllegalBlockSizeException: " + ex.getMessage()); } catch (BadPaddingException ex) { throw new IllegalStateException("BadPaddingException: " + ex.getMessage()); } }
public static InputStream decrypt(InputStream input, byte[] password, byte[] salt) { try { Cipher c = init(password, salt, Cipher.DECRYPT_MODE); return new CipherInputStream(input, c); } catch (BadPaddingException e) { throw new SecurityException("Error decrypting a secret: " + e.getMessage() + ". Invalid input data and/or a password."); } catch (GeneralSecurityException e) { throw new SecurityException("Error decrypting a secret: " + e.getMessage()); } }
@Override public byte[] getSignature() { try { return cipher.doFinal(); } catch (IllegalBlockSizeException ex) { throw new IllegalStateException("IllegalBlockSizeException: " + ex.getMessage()); } catch (BadPaddingException ex) { throw new IllegalStateException("BadPaddingException: " + ex.getMessage()); } }
private static byte[] encryptWithKey(byte[] key, byte[] data) { try { final Cipher c = initCipher(key); return c.doFinal(data); } catch (IllegalBlockSizeException e) { throw new IllegalStateException(e.getMessage()); } catch (BadPaddingException e) { throw new IllegalStateException(e.getMessage()); } }
private static byte[] encryptWithKey(byte[] key, byte[] data, boolean noPadding, byte[] iv) { try { final Cipher c = initCipher(key, noPadding, iv); return c.doFinal(data); } catch (IllegalBlockSizeException e) { throw new IllegalStateException(e.getMessage()); } catch (BadPaddingException e) { throw new IllegalStateException(e.getMessage()); } }
protected byte[] engineWrap( Key key) throws IllegalBlockSizeException, java.security.InvalidKeyException { byte[] encoded = key.getEncoded(); if (encoded == null) { throw new InvalidKeyException("Cannot wrap key, null encoding."); } try { return engineDoFinal(encoded, 0, encoded.length); } catch (BadPaddingException e) { throw new IllegalBlockSizeException(e.getMessage()); } }
protected byte[] engineWrap( Key key) throws IllegalBlockSizeException, InvalidKeyException { byte[] encoded = key.getEncoded(); if (encoded == null) { throw new InvalidKeyException("Cannot wrap key, null encoding."); } try { return engineDoFinal(encoded, 0, encoded.length); } catch (BadPaddingException e) { throw new IllegalBlockSizeException(e.getMessage()); } }
protected byte[] engineWrap( Key key) throws IllegalBlockSizeException, java.security.InvalidKeyException { byte[] encoded = key.getEncoded(); if (encoded == null) { throw new InvalidKeyException("Cannot wrap key, null encoding."); } try { return engineDoFinal(encoded, 0, encoded.length); } catch (BadPaddingException e) { throw new IllegalBlockSizeException(e.getMessage()); } }
protected byte[] engineWrap( Key key) throws IllegalBlockSizeException, java.security.InvalidKeyException { byte[] encoded = key.getEncoded(); if (encoded == null) { throw new InvalidKeyException("Cannot wrap key, null encoding."); } try { return engineDoFinal(encoded, 0, encoded.length); } catch (BadPaddingException e) { throw new IllegalBlockSizeException(e.getMessage()); } }
protected byte[] engineWrap( Key key) throws IllegalBlockSizeException, InvalidKeyException { byte[] encoded = key.getEncoded(); if (encoded == null) { throw new InvalidKeyException("Cannot wrap key, null encoding."); } try { return engineDoFinal(encoded, 0, encoded.length); } catch (BadPaddingException e) { throw new IllegalBlockSizeException(e.getMessage()); } }
protected byte[] engineWrap( Key key) throws IllegalBlockSizeException, java.security.InvalidKeyException { byte[] encoded = key.getEncoded(); if (encoded == null) { throw new InvalidKeyException("Cannot wrap key, null encoding."); } try { return engineDoFinal(encoded, 0, encoded.length); } catch (BadPaddingException e) { throw new IllegalBlockSizeException(e.getMessage()); } }
public static String encrypt(String data, byte[] aesKey, byte[] iv) throws BraintreeEncryptionException { SecretKeySpec key = new SecretKeySpec(aesKey, ALGORITHM); Cipher cipher = aesCipher(); try { IvParameterSpec ivParamSpec = new IvParameterSpec(iv); cipher.init(Cipher.ENCRYPT_MODE, key, ivParamSpec); byte[] encryptedBytes = cipher.doFinal(data.getBytes()); byte[] buffer = Arrays.copyOf(iv, iv.length + encryptedBytes.length); System.arraycopy(encryptedBytes, 0, buffer, iv.length, encryptedBytes.length); return new String(Base64.encode(buffer)); } catch (InvalidKeyException e) { throw new BraintreeEncryptionException("Invalid Key: " + e.getMessage()); } catch (BadPaddingException e) { throw new BraintreeEncryptionException("Bad Padding: " + e.getMessage()); } catch (IllegalBlockSizeException e) { throw new BraintreeEncryptionException("Illegal Block Size: " + e.getMessage()); } catch (InvalidAlgorithmParameterException e) { throw new BraintreeEncryptionException("Invalid Algorithm: " + e.getMessage()); } }
public static String encrypt(byte[] data, String publicKeyString) throws BraintreeEncryptionException { Cipher rsa; try { rsa = Cipher.getInstance(TRANSFORMATION); PublicKey publicKey = publicKey(publicKeyString); rsa.init(Cipher.ENCRYPT_MODE, publicKey); byte[] encodedData = Base64.encode(data); byte[] encryptedData = rsa.doFinal(encodedData); return new String(Base64.encode(encryptedData)); } catch (NoSuchAlgorithmException e) { throw new BraintreeEncryptionException("No Such Algorithm: " + e.getMessage()); } catch (NoSuchPaddingException e) { throw new BraintreeEncryptionException("No Such Padding: " + e.getMessage()); } catch (InvalidKeyException e) { throw new BraintreeEncryptionException("Invalid Key: " + e.getMessage()); } catch (IllegalBlockSizeException e) { throw new BraintreeEncryptionException("Illegal Block Size: " + e.getMessage()); } catch (BadPaddingException e) { throw new BraintreeEncryptionException("Bad Padding: " + e.getMessage()); } }
private byte[] rsaX509Sign(byte[] dataToSign) throws P11TokenException { ConcurrentBagEntry<Cipher> cipher; try { cipher = rsaCiphers.borrow(5000, TimeUnit.MILLISECONDS); } catch (InterruptedException ex) { throw new P11TokenException("could not take any idle signer"); } if (cipher == null) { throw new P11TokenException("no idle RSA cipher available"); } try { return cipher.value().doFinal(dataToSign); } catch (BadPaddingException ex) { throw new P11TokenException("BadPaddingException: " + ex.getMessage(), ex); } catch (IllegalBlockSizeException ex) { throw new P11TokenException("IllegalBlockSizeException: " + ex.getMessage(), ex); } finally { rsaCiphers.requite(cipher); } }
private byte[] rsaX509Sign(final byte[] dataToSign) throws P11TokenException { ConcurrentBagEntry<Cipher> cipher; try { cipher = rsaCiphers.borrow(5000, TimeUnit.MILLISECONDS); } catch (InterruptedException ex) { throw new P11TokenException("could not take any idle signer"); } if (cipher == null) { throw new P11TokenException("no idle RSA cipher available"); } try { return cipher.value().doFinal(dataToSign); } catch (BadPaddingException ex) { throw new P11TokenException("BadPaddingException: " + ex.getMessage(), ex); } catch (IllegalBlockSizeException ex) { throw new P11TokenException("IllegalBlockSizeException: " + ex.getMessage(), ex); } finally { rsaCiphers.requite(cipher); } }