com.facebook.crypto.util.SystemNativeCryptoLibrary Java Examples

The following examples show how to use com.facebook.crypto.util.SystemNativeCryptoLibrary. 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: CryptoUtils.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
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();
    }
 
Example #2
Source File: CryptoUtils.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
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();
    }
 
Example #3
Source File: CryptoUtils.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
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();
    }
 
Example #4
Source File: CryptoUtils.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
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();
    }
 
Example #5
Source File: ConcealCrypto.java    From droid-stealth with GNU General Public License v2.0 4 votes vote down vote up
public ConcealCrypto(Context context) {
	crypto = new Crypto(
			new SharedPrefsBackedKeyChain(context),
			new SystemNativeCryptoLibrary());
}