public BaseConcealPreference( final Crypto crypto, final SharedPreferences preferences, final String key, final T defaultValue) { this.defaultValue = defaultValue; this.stringPreference = new ConcealStringPreference(crypto, preferences, key, String.valueOf(defaultValue)); }
public ConcealIntPreference( final Crypto crypto, final SharedPreferences preferences, final String key, final int defaultValue) { super(crypto, preferences, key, defaultValue); }
public ConcealFloatPreference( final Crypto crypto, final SharedPreferences preferences, final String key, final float defaultValue) { super(crypto, preferences, key, defaultValue); }
public ConcealStringSetPreference( final Crypto crypto, final SharedPreferences preferences, final String key, final Set<String> defaultValue) { super(preferences, key, defaultValue); this.crypto = crypto; this.entity = Entity.create(key); }
public ConcealBooleanPreference( final Crypto crypto, final SharedPreferences preferences, final String key, final boolean defaultValue) { super(crypto, preferences, key, defaultValue); }
public ConcealLongPreference( final Crypto crypto, final SharedPreferences preferences, final String key, final long defaultValue) { super(crypto, preferences, key, defaultValue); }
public ConcealStringPreference( final Crypto crypto, final SharedPreferences preferences, final String key, final String defaultValue) { super(preferences, key, defaultValue); this.crypto = crypto; this.entity = Entity.create(key); }
@Before public void setUp() throws Exception { SoLoader.init(InstrumentationRegistry.getContext(), false); final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(InstrumentationRegistry.getContext()); final Crypto crypto = AndroidConceal .get() .createDefaultCrypto(new SharedPrefsBackedKeyChain( InstrumentationRegistry.getContext(), CryptoConfig.KEY_256 )); factory = new ConcealPreferenceFactory(crypto, prefs); }
@Before public void setUp() throws Exception { final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(InstrumentationRegistry.getContext()); final Crypto crypto = AndroidConceal .get() .createDefaultCrypto(new SharedPrefsBackedKeyChain( InstrumentationRegistry.getContext(), CryptoConfig.KEY_256 )); factory = new ConcealPreferenceFactory(crypto, prefs); }
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 Crypto getCrypto(){ return crypto; }
public ConcealIntPreference( final Crypto crypto, final SharedPreferences preferences, final String key) { this(crypto, preferences, key, 0); }
public ConcealFloatPreference( final Crypto crypto, final SharedPreferences preferences, final String key) { this(crypto, preferences, key, 0f); }
public ConcealStringSetPreference( final Crypto crypto, final SharedPreferences preferences, final String key) { this(crypto, preferences, key, null); }
public ConcealBooleanPreference( final Crypto crypto, final SharedPreferences preferences, final String key) { this(crypto, preferences, key, false); }
public ConcealLongPreference( final Crypto crypto, final SharedPreferences preferences, final String key) { this(crypto, preferences, key, 0L); }
public ConcealStringPreference( final Crypto crypto, final SharedPreferences preferences, final String key) { this(crypto, preferences, key, null); }
public ConcealPreferenceFactory( final Crypto crypto, final SharedPreferences sharedPreferences) { this.crypto = crypto; this.sharedPreferences = sharedPreferences; }
public static String encrypt(Crypto crypto, String alias, String plainText) throws IOException, KeyChainException, CryptoInitializationException { final byte[] bytes = crypto.encrypt(plainText.getBytes(ENCODING), Entity.create(alias)); return Base64.encodeToString(bytes, BASE64_FLAG); }
public static String decrypt(Crypto crypto, String alias, String encryptedText) throws IOException, KeyChainException, CryptoInitializationException { final byte[] bytes = crypto.decrypt(Base64.decode(encryptedText, BASE64_FLAG), Entity.create(alias)); return new String(bytes, ENCODING); }
public PreferenceUtils(Gson gson, SharedPreferences preferences, Crypto crypto) { mGson = gson; mPreference = preferences; mCrypto = crypto; }
public ConcealCrypto(Context context) { crypto = new Crypto( new SharedPrefsBackedKeyChain(context), new SystemNativeCryptoLibrary()); }