use of com.facebook.android.crypto.keychain.SharedPrefsBackedKeyChain in project hawk by orhanobut.
the class ConcealTest method setup.
@Before
public void setup() {
Context context = InstrumentationRegistry.getContext();
SharedPrefsBackedKeyChain keyChain = new SharedPrefsBackedKeyChain(context, CryptoConfig.KEY_256);
crypto = AndroidConceal.get().createDefaultCrypto(keyChain);
}
use of com.facebook.android.crypto.keychain.SharedPrefsBackedKeyChain in project TeamCityApp by vase4kin.
the class AppModule method providesCryptoManager.
@VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE)
@Provides
@Singleton
protected CryptoManager providesCryptoManager() {
KeyChain keyChain = new SharedPrefsBackedKeyChain(mApplication.getApplicationContext(), CryptoConfig.KEY_256);
Crypto crypto = AndroidConceal.get().createDefaultCrypto(keyChain);
return new CryptoManagerImpl(crypto);
}
use of com.facebook.android.crypto.keychain.SharedPrefsBackedKeyChain in project conceal by facebook.
the class SharedPrefsBackedKeyChainTest method testLegacy128Bits.
public void testLegacy128Bits() throws Exception {
KeyChain keyChain = new SharedPrefsBackedKeyChain(this.getInstrumentation().getContext());
// destroy keys if they were present in prefs from previous test
keyChain.destroyKeys();
byte[] key = keyChain.getCipherKey();
assertEquals(16, key.length);
KeyChain keyChain2 = new SharedPrefsBackedKeyChain(this.getInstrumentation().getContext());
byte[] key2 = keyChain.getCipherKey();
assertTrue(Arrays.equals(key, key2));
}
use of com.facebook.android.crypto.keychain.SharedPrefsBackedKeyChain in project LabDayApp by jakdor.
the class ProjectRepository method loadAccessToken.
/**
* Loads access token and decrypts it with Conceal
* @param context required for SharedPreferences/Conceal
* @return boolean success/fail
*/
public boolean loadAccessToken(Context context) {
KeyChain keyChain = new SharedPrefsBackedKeyChain(context, CryptoConfig.KEY_256);
Crypto crypto = AndroidConceal.get().createDefaultCrypto(keyChain);
try {
byte[] encryptedToken = readFile(context, "lab");
if (encryptedToken == null) {
Timber.e("Access token not found");
return false;
} else if (encryptedToken.length == 0) {
Timber.e("Access token not available");
return false;
}
byte[] plainToken = crypto.decrypt(encryptedToken, Entity.create("token"));
this.accessToken = new String(plainToken);
Timber.i("Loaded and decrypted access token");
} catch (Exception e) {
Timber.wtf("unable to decipher access token");
return false;
}
return true;
}
use of com.facebook.android.crypto.keychain.SharedPrefsBackedKeyChain in project conceal by facebook.
the class SharedPrefsBackedKeyChainTest method test256Bits.
public void test256Bits() throws Exception {
KeyChain keyChain = new SharedPrefsBackedKeyChain(this.getInstrumentation().getContext(), CryptoConfig.KEY_256);
// destroy keys if they were present in prefs from previous test
keyChain.destroyKeys();
byte[] key = keyChain.getCipherKey();
assertEquals(32, key.length);
KeyChain keyChain2 = new SharedPrefsBackedKeyChain(this.getInstrumentation().getContext());
byte[] key2 = keyChain.getCipherKey();
assertTrue(Arrays.equals(key, key2));
}
Aggregations