com.facebook.crypto.exception.CryptoInitializationException Java Examples
The following examples show how to use
com.facebook.crypto.exception.CryptoInitializationException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SecurePreferences.java From secure-preferences with Apache License 2.0 | 6 votes |
private String encrypt(final String plainText) { if (TextUtils.isEmpty(plainText)) { return plainText; } byte[] cipherText = null; if (!crypto.isAvailable()) { log(Log.WARN, "encrypt: crypto not available"); return null; } try { cipherText = crypto.encrypt(plainText.getBytes(), entity); } catch (KeyChainException | CryptoInitializationException | IOException e) { log(Log.ERROR, "encrypt: " + e); } return cipherText != null ? Base64.encodeToString(cipherText, Base64.DEFAULT) : null; }
Example #2
Source File: SecurePreferences.java From secure-preferences with Apache License 2.0 | 6 votes |
private String decrypt(final String encryptedText) { if (TextUtils.isEmpty(encryptedText)) { return encryptedText; } byte[] plainText = null; if (!crypto.isAvailable()) { log(Log.WARN, "decrypt: crypto not available"); return null; } try { plainText = crypto.decrypt(Base64.decode(encryptedText, Base64.DEFAULT), entity); } catch (KeyChainException | CryptoInitializationException | IOException e) { log(Log.ERROR, "decrypt: " + e); } return plainText != null ? new String(plainText) : null; }
Example #3
Source File: ConcealCrypto.java From droid-stealth with GNU General Public License v2.0 | 5 votes |
/** * Encrypts the unencrypted file. Can throw a lot of errors * * @param encrypted * @param unencrypted * @param entityName * @throws IOException * @throws CryptoInitializationException * @throws KeyChainException */ @Override public void encrypt(File encrypted, File unencrypted, String entityName) throws IOException, CryptoInitializationException, KeyChainException { doFileChecks(unencrypted, encrypted); FileInputStream from = new FileInputStream(unencrypted); // Stream to read from source OutputStream to = crypto.getCipherOutputStream(new FileOutputStream(encrypted), new Entity(entityName)); // Stream to write to destination copyStreams(from, to); }
Example #4
Source File: ConcealCrypto.java From droid-stealth with GNU General Public License v2.0 | 5 votes |
/** * Decrypts the encrypted file. Can also throw a lot of errors * * @param encrypted * @param unencrypted * @param entityName * @throws IOException * @throws CryptoInitializationException * @throws KeyChainException */ @Override public void decrypt(File encrypted, File unencrypted, String entityName) throws IOException, CryptoInitializationException, KeyChainException { doFileChecks(encrypted, unencrypted); InputStream from = crypto.getCipherInputStream(new FileInputStream(encrypted), new Entity(entityName)); FileOutputStream to = new FileOutputStream(unencrypted); copyStreams(from, to); }
Example #5
Source File: ICrypto.java From droid-stealth with GNU General Public License v2.0 | 2 votes |
/** * Encrypts a file input stream to the given file * @param encrypted file to be written to. Cannot be a directory * @param unencrypted the original file to be encrypted * @exception java.io.IOException thrown when the operation fails, either because the encrypted * file already exists, or something failed during encryption */ public void encrypt(File encrypted, File unencrypted, String entityName) throws IOException, CryptoInitializationException, KeyChainException;
Example #6
Source File: ICrypto.java From droid-stealth with GNU General Public License v2.0 | votes |
public void decrypt(File encrypted, File unencrypted, String entityName) throws IOException, CryptoInitializationException, KeyChainException;