Skip to content

Instantly share code, notes, and snippets.

include(default)
standalone_toolchain=/opt/android-ndk-toolchains/arm-27
ndk_home=/opt/android-ndk
api_level=27
target_host=arm-linux-androideabi
cc_compiler=clang
cxx_compiler=clang++
target_specific_flags=-mfpu=neon
@Diederikjh
Diederikjh / Cryptography.java
Last active February 23, 2024 10:07
Single class that handles encryption and decryption with keys using the Android `Keystore` API. Mostly inspired by this [blog post](https://medium.com/@ericfu/securely-storing-secrets-in-an-android-application-501f030ae5a3). This was tested with API 18 and 25 level emulator (and a level 23 device).
package com.example.yourapp;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Build;
import android.security.KeyPairGeneratorSpec;
import android.security.keystore.KeyGenParameterSpec;
import android.security.keystore.KeyProperties;
import android.support.annotation.RequiresApi;