throw new IOException(e.getMessage()); } catch (IllegalBlockSizeException e) { throw new IOException(e.getMessage()); } finally { if (out != null) {
throw new InvalidKeyException(e.getMessage()); } catch (IllegalBlockSizeException e) { throw new InvalidKeyException(e.getMessage()); } catch (BadPaddingException e) { throw new InvalidKeyException(e.getMessage());
throw new InvalidKeyException(e.getMessage()); } catch (IllegalBlockSizeException e) { throw new InvalidKeyException(e.getMessage()); } catch (BadPaddingException e) { throw new InvalidKeyException(e.getMessage());
throw new InvalidKeyException(e.getMessage()); } catch (IllegalBlockSizeException e) { throw new InvalidKeyException(e.getMessage()); } catch (BadPaddingException e) { throw new InvalidKeyException(e.getMessage());
throw new InvalidKeySpecException(e.getMessage()); } catch (IllegalBlockSizeException e) { 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()); } }
@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 String decrypt(String value) { try { Cipher cipher = Cipher.getInstance(ALGORITHM); cipher.init(Cipher.DECRYPT_MODE, generateKey()); byte[] decryptedValue64 = Base64.decodeBase64(value); byte[] decryptedByteValue = cipher.doFinal(decryptedValue64); String decryptedValue = new String(decryptedByteValue, "UTF-8"); return decryptedValue; } catch (IllegalBlockSizeException ex) { _logger.warn("Exception: '{}'", ex.getMessage()); _logger.debug("Exception, ", ex); } catch (Exception ex) { _logger.error("Exception, ", ex); } return null; }
public static String decrypt(String value) { try { Cipher cipher = Cipher.getInstance(ALGORITHM); cipher.init(Cipher.DECRYPT_MODE, generateKey()); byte[] decryptedValue64 = Base64.decodeBase64(value); byte[] decryptedByteValue = cipher.doFinal(decryptedValue64); String decryptedValue = new String(decryptedByteValue, "UTF-8"); return decryptedValue; } catch (IllegalBlockSizeException ex) { _logger.warn("Exception: '{}'", ex.getMessage()); _logger.debug("Exception, ", ex); } catch (Exception ex) { _logger.error("Exception, ", ex); } return null; }
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()); } }
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()); } }
@Override protected String doInBackground(PasswordDatabase... params) { String message = null; try { synchronized (UPMApplication.sDataLock) { params[0].save(); } // Ask the BackupManager to backup the database using // Google's cloud backup service. Log.i("SaveDatabaseAsyncTask", "Calling BackupManager().dataChanged()"); ((UPMApplication) activity.getApplication()).getBackupManager().dataChanged(); } catch (IllegalBlockSizeException e) { Log.e("SaveDatabaseAsyncTask", e.getMessage(), e); message = String.format(activity.getString(R.string.problem_saving_db), e.getMessage()); } catch (BadPaddingException e) { Log.e("SaveDatabaseAsyncTask", e.getMessage(), e); message = String.format(activity.getString(R.string.problem_saving_db), e.getMessage()); } catch (IOException e) { Log.e("SaveDatabaseAsyncTask", e.getMessage(), e); message = String.format(activity.getString(R.string.problem_saving_db), e.getMessage()); } return message; }
/** * Encrypts the secret key (symmetric key) held inside the OxalisCipher instance using the supplied PublicKey, after * which the resulting wrapped secret key is transformed into a hex string suitable for transmission, persistence etc. * * @param publicKey the public asymmetric key to use for encrypting the secret symmetric key * @param oxalisCipher the instance of OxalisCipher in which the secret symmetric key is held. * @return */ public String getWrappedSymmetricKeyAsString(PublicKey publicKey, OxalisCipher oxalisCipher) { try { Cipher cipher = Cipher.getInstance(StatisticsKeyTool.ASYMMETRIC_KEY_ALGORITHM); cipher.init(Cipher.WRAP_MODE, publicKey); SecretKey secretKey = oxalisCipher.getSecretKey(); byte[] encodedBytes = cipher.wrap(secretKey); return new String(Hex.encodeHex(encodedBytes)); } catch (NoSuchAlgorithmException e) { throw new IllegalStateException("Unable to create cipher with algorithm: " + StatisticsKeyTool.ASYMMETRIC_KEY_ALGORITHM, e); } catch (NoSuchPaddingException e) { throw new IllegalStateException("Unable to create cipher with default padding for algorithm " + StatisticsKeyTool.ASYMMETRIC_KEY_ALGORITHM, e); } catch (InvalidKeyException e) { throw new IllegalStateException("The public key is invalid " + e.getMessage(), e); } catch (IllegalBlockSizeException e) { throw new IllegalStateException("Error during encryption of symmetric key: " + e.getMessage(), e); } }
public String unobfuscate(String obfuscated, String key) throws ValidationException { if (obfuscated == null) { return null; } try { String result = new String(mDecryptor.doFinal(Base64.decode(obfuscated)), UTF8); // Check for presence of header. This serves as a final integrity check, for cases // where the block size is correct during decryption. int headerIndex = result.indexOf(header+key); if (headerIndex != 0) { throw new ValidationException("Header not found (invalid data or key)" + ":" + obfuscated); } return result.substring(header.length()+key.length(), result.length()); } catch (Base64DecoderException e) { throw new ValidationException(e.getMessage() + ":" + obfuscated); } catch (IllegalBlockSizeException e) { throw new ValidationException(e.getMessage() + ":" + obfuscated); } catch (BadPaddingException e) { throw new ValidationException(e.getMessage() + ":" + obfuscated); } catch (UnsupportedEncodingException e) { throw new RuntimeException("Invalid environment", e); } } }
public String unobfuscate(String obfuscated, String key) throws ValidationException { if (obfuscated == null) { return null; } try { String result = new String(mDecryptor.doFinal(Base64.decode(obfuscated)), UTF8); // Check for presence of header. This serves as a final integrity check, for cases // where the block size is correct during decryption. int headerIndex = result.indexOf(header + key); if (headerIndex != 0) { throw new ValidationException("Header not found (invalid data or key)" + ":" + obfuscated); } return result.substring(header.length() + key.length(), result.length()); } catch (Base64DecoderException e) { throw new ValidationException(e.getMessage() + ":" + obfuscated); } catch (IllegalBlockSizeException e) { throw new ValidationException(e.getMessage() + ":" + obfuscated); } catch (BadPaddingException e) { throw new ValidationException(e.getMessage() + ":" + obfuscated); } catch (UnsupportedEncodingException e) { throw new RuntimeException("Invalid environment", e); } } }
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()); } }
public byte[] encryptKeyData(byte[] key, byte[] keyData, int keyOff, int keyLen) throws PGPException { try { c = helper.createCipher(PGPUtil.getSymmetricCipherName(this.encAlgorithm) + "/CFB/NoPadding"); c.init(Cipher.ENCRYPT_MODE, JcaJcePGPUtil.makeSymmetricKey(this.encAlgorithm, key), this.random); iv = c.getIV(); return c.doFinal(keyData, keyOff, keyLen); } catch (IllegalBlockSizeException e) { throw new PGPException("illegal block size: " + e.getMessage(), e); } catch (BadPaddingException e) { throw new PGPException("bad padding: " + e.getMessage(), e); } catch (InvalidKeyException e) { throw new PGPException("invalid key: " + e.getMessage(), e); } }
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); } }
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); } }