Skip to content

hbazargan/SecureStorage

Repository files navigation

This project is based on Hawk project with some changes. The default encryption was replaced by a new encryption method which is based on AndroidKeyStore. Also, the new encryption method inherits from Secrets Keeper project.

The below diagram illustrates steps of data storing which uses in this module.

You can implement your custom module based on the contracts for each sections of above diagram then inject it to module builder.

The below diagram illustrates flow of decision making in order to create keys.

Usage

Initialize

SecureStorage.SecureStorageBuilder builder = new SecureStorage.SecureStorageBuilder(getApplicationContext()).build();

By default Symmetric key (AES) is used to encrypt/decrypt data. You can change it as below:

SecureStorage.SecureStorageBuilder builder = new SecureStorage.SecureStorageBuilder(getApplicationContext());
        builder.setAlgorithm(AlgorithmType.ASYMMETRIC);
        secureStorage = builder.build();

Also, you can add an LogInterceptor in order to log operations.

        secureStorage = builder.setLogInterceptorModuleContract(new LogInterceptorModuleContract() {
            @Override public void onLog(String message) {
                Log.d("SecureStorage", message);
            }
        }).build();

Put data

secureStorage.put("Key", "Value");

Get data

secureStorage.get("key");

Get data count

secureStorage.count();

Get existence of data

secureStorage.contains("key");

Delete data

secureStorage.delete("key");

Note

SDK limits

The encryption module is based on AndroidKeyStore, thus it doesn't supported APIs below 18 because there is no infrastructure for AndroidKeyStore. In this situation(APIs below 18), the encryption module only (encrypt/decrypt)s data based on Base64.

Encryption/Decryption algorithms

By default, AES and RSA are used to encrypt/decrypt data.

Encryption/Decryption size limit

There is no limit to encrypt/decrypt by Symmetric keys. If you want to use Asymmetric keys, the data size limit will be 245 bytes.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages