ICSNativeStringEncryption(String password) { this.password = password; this.hashing = new Hashing(); this.encoding = new Encoding(); SystemNativeCryptoLibrary nativeCryptoLibrary = new SystemNativeCryptoLibrary(); MemoryKeyChain keyChain = new MemoryKeyChain(CryptoConfig.KEY_256, password, nativeCryptoLibrary); this.crypto = new Crypto(keyChain, nativeCryptoLibrary, CryptoConfig.KEY_256); }
public DiskCache(Context context, String category) { mCrypto = new Crypto( new SharedPrefsBackedKeyChain(context), new SystemNativeCryptoLibrary()); mCacheDir = new File(category); if (mCacheDir.exists()) { isLazyInit = true; mCache = new DiskBasedCache(mCacheDir, DEFAULT_DISK_USAGE_BYTES); initialize(); } }
public CryptoManager(Context context, String path, String password) { this.path = path; this.crypto = new Crypto( new SharedPrefsBackedKeyChain(context), new SystemNativeCryptoLibrary()); entity = new Entity(password); checkPathExists(); }
public static void encryptingContent(Context context, File file, byte[] plainTextBytes) throws Exception { // Creates a new Crypto object with default implementations of // a key chain as well as native library. Crypto crypto = new Crypto( new SharedPrefsBackedKeyChain(context), new SystemNativeCryptoLibrary()); // Check for whether the crypto functionality is available // This might fail if android does not load libaries correctly. if (!crypto.isAvailable()) { return; } OutputStream fileStream = new BufferedOutputStream( new FileOutputStream(file)); // Creates an output stream which encrypts the data as // it is written to it and writes it out to the file. OutputStream outputStream = crypto.getCipherOutputStream( fileStream, new Entity("TEST1")); // Write plaintext to it. outputStream.write(plainTextBytes); outputStream.close(); }
public static void decryptingContent(Context context, File file, String newPath) throws Exception { // Get the file to which ciphertext has been written. FileInputStream fileStream = new FileInputStream(file); Crypto crypto = new Crypto( new SharedPrefsBackedKeyChain(context), new SystemNativeCryptoLibrary()); // Creates an input stream which decrypts the data as // it is read from it. InputStream inputStream = crypto.getCipherInputStream( fileStream, new Entity("TEST1")); // Read into a byte array. int read; byte[] buffer = new byte[1024]; // You must read the entire stream to completion. // The verification is done at the end of the stream. // Thus not reading till the end of the stream will cause // a security bug. FileOutputStream fs = new FileOutputStream(newPath); while ((read = inputStream.read(buffer)) != -1) { fs.write(buffer, 0, read); } inputStream.close(); }
public ConcealCrypto(Context context) { crypto = new Crypto( new SharedPrefsBackedKeyChain(context), new SystemNativeCryptoLibrary()); }