use of com.facebook.crypto.util.SystemNativeCryptoLibrary in project conceal by facebook.
the class NativeGCMCipherInputStreamTest method setUp.
protected void setUp() throws Exception {
super.setUp();
mNativeCryptoLibrary = new SystemNativeCryptoLibrary();
KeyChain keyChain = new FakeKeyChain();
mCrypto = new Crypto(keyChain, mNativeCryptoLibrary);
mIV = keyChain.getNewIV();
mKey = keyChain.getCipherKey();
// Encrypt some data before each test.
mData = new byte[CryptoTestUtils.NUM_DATA_BYTES];
Random random = new Random();
random.nextBytes(mData);
ByteArrayOutputStream cipherOutputStream = new ByteArrayOutputStream();
OutputStream outputStream = mCrypto.getCipherOutputStream(cipherOutputStream, new Entity(CryptoTestUtils.ENTITY_NAME));
outputStream.write(mData);
outputStream.close();
mCipheredData = cipherOutputStream.toByteArray();
mCipherInputStream = new ByteArrayInputStream(mCipheredData);
}
use of com.facebook.crypto.util.SystemNativeCryptoLibrary in project conceal by facebook.
the class NativeGCMCipherOutputStreamTest method setUp.
protected void setUp() throws Exception {
super.setUp();
mNativeCryptoLibrary = new SystemNativeCryptoLibrary();
KeyChain keyChain = new FakeKeyChain();
mKey = keyChain.getCipherKey();
mIV = keyChain.getNewIV();
mCrypto = new Crypto(keyChain, mNativeCryptoLibrary);
mData = new byte[CryptoTestUtils.NUM_DATA_BYTES];
mCipherOutputStream = new ByteArrayOutputStream();
}
use of com.facebook.crypto.util.SystemNativeCryptoLibrary in project UltimateAndroid by cymcsg.
the class FakeKeyChain method encryptingContent.
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());
// 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();
}
use of com.facebook.crypto.util.SystemNativeCryptoLibrary in project UltimateAndroid by cymcsg.
the class FakeKeyChain method decryptingContent.
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();
}
Aggregations