use of com.facebook.crypto.keychain.KeyChain in project conceal by facebook.
the class SimpleDecryptTest method setUp.
protected void setUp() throws Exception {
super.setUp();
SoLoader.init(this.getInstrumentation().getContext(), false);
KeyChain keyChain = new FakeKeyChain();
mCrypto = AndroidConceal.get().createCrypto128Bits(keyChain);
mIV = keyChain.getNewIV();
mKey = keyChain.getCipherKey();
// Encrypt some data before each test.
mData = new byte[CryptoTestUtils.NUM_DATA_BYTES];
ByteArrayOutputStream cipherOutputStream = new ByteArrayOutputStream();
OutputStream outputStream = mCrypto.getCipherOutputStream(cipherOutputStream, new Entity(CryptoTestUtils.ENTITY_NAME));
outputStream.write(mData);
outputStream.close();
mCipheredData = cipherOutputStream.toByteArray();
}
use of com.facebook.crypto.keychain.KeyChain in project LabDayApp by jakdor.
the class ProjectRepository method saveAccessToken.
/**
* Saves access token encrypted with Conceal
* @param token access token retrieved after successful login
* @param context required for SharedPreferences/Conceal
*/
public void saveAccessToken(String token, Context context) {
if (token.equals("-1")) {
this.accessToken = token;
Timber.e("bad access token");
return;
}
KeyChain keyChain = new SharedPrefsBackedKeyChain(context, CryptoConfig.KEY_256);
Crypto crypto = AndroidConceal.get().createDefaultCrypto(keyChain);
try {
byte[] tokenBytes = token.getBytes(Charset.forName("UTF-8"));
byte[] encryptedToken = crypto.encrypt(tokenBytes, Entity.create("token"));
FileOutputStream outputStream = context.openFileOutput("lab", Context.MODE_PRIVATE);
outputStream.write(encryptedToken);
outputStream.close();
Timber.i("Successful login, access token saved");
} catch (Exception e) {
Timber.wtf("unable to save access token");
}
this.accessToken = token;
}
Aggregations