@WorkerThread
public class StringCipher
extends java.lang.Object
This uses SharedPreferences to save the salt of encryption. Please specify a unique name
as the constructor parameter that represents Shared Preference name.
Either first access of encrypt(Context, String), decrypt(Context, String) or
initialize(Context) is very slow because there is secret key generation with PBKDF2.
We recommend that you initialize an instance of this class beforehand and cache it.
| Constructor and Description |
|---|
StringCipher(java.lang.String sharedPreferenceName) |
StringCipher(java.lang.String sharedPreferenceName,
int pbkdf2IterationCount,
boolean isSerialIncludedInDevicePackageSpecificId) |
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
decrypt(Context context,
java.lang.String b64CipherText) |
java.lang.String |
encrypt(Context context,
java.lang.String plainText) |
void |
initialize(Context context) |
public StringCipher(@NonNull
java.lang.String sharedPreferenceName)
public StringCipher(@NonNull
java.lang.String sharedPreferenceName,
int pbkdf2IterationCount,
boolean isSerialIncludedInDevicePackageSpecificId)
sharedPreferenceName - shared pref name used to save saltpbkdf2IterationCount - number of iteration used for encryptionisSerialIncludedInDevicePackageSpecificId - Indicates if we should also include Build.Serial as an identifier to generate
the device Id.
Note : This field should always be false as it is deprecated and
returns UNKNOWN in some cases from Android SDK >= 27public void initialize(@NonNull
Context context)
@NonNull
public java.lang.String encrypt(@NonNull
Context context,
@NonNull
java.lang.String plainText)
@NonNull
public java.lang.String decrypt(@NonNull
Context context,
@NonNull
java.lang.String b64CipherText)