Skip to content

Instantly share code, notes, and snippets.

View smokelaboratory's full-sized avatar
🎵

Sumeet Rukeja smokelaboratory

🎵
View GitHub Profile
@smokelaboratory
smokelaboratory / enc_shared_prefs.xml
Created March 16, 2020 04:13
Encrypted SharedPreferences XML
<map>
<string name="ASx6qQDkW3HGEejBxpA3jWAxQl/FKavIIt50b5QuYQY=">AUcTQT3WS49w2VFXDhjIUHv6QyTfkPAVACxp5GijeGNLOIJOMRCIHIJjpaB3</string>
</map>
@smokelaboratory
smokelaboratory / shared_prefs_obj.kt
Created March 16, 2020 04:12
SharedPreferences object
securedSharedPrefs = EncryptedSharedPreferences.create(
"values_secured", //xml file name
master_key, //master key
this, //context
AES256_SIV, //key encryption technique
AES256_GCM //value encryption technique
)
@smokelaboratory
smokelaboratory / enc_shared_prefs.kt
Created March 16, 2020 04:11
Encrypt Decrypt SharedPreferences
//to save a value
securedSharedPrefs.edit().putString("name", "android").apply()
//to fetch a value
securedSharedPrefs.getString("name", "")
@smokelaboratory
smokelaboratory / enc_dec_file.kt
Created March 16, 2020 04:09
Encrypt Decrypt file
//save data
encryptedFile.openFileOutput().use { outputstream ->
outputstream.write(et_data.text.toString().toByteArray())
}
//read data
encryptedFile.openFileInput().use { inputstream ->
tv_result.text = String(inputstream.readBytes(), Charsets.UTF_8)
}
@smokelaboratory
smokelaboratory / biometric_prompt.kt
Created March 16, 2020 04:08
Biometric Prompt method
override fun onAuthenticationSucceeded(result: AuthenticationResult) {
super.onAuthenticationSucceeded(result)
// key is unlocked
}
@smokelaboratory
smokelaboratory / shared_prefs.xml
Created March 16, 2020 04:06
SharedPreferences
<map>
<string name="email">test@gmail.com</string>
</map>
@smokelaboratory
smokelaboratory / enc_file.kt
Created March 13, 2020 06:26
JetSec encrypted file object
encryptedFile = EncryptedFile.Builder(
secretFile,
applicationContext,
MasterKeys.getOrCreate(MasterKeys.AES256_GCM_SPEC), //master key
EncryptedFile.FileEncryptionScheme.AES256_GCM_HKDF_4KB
)
.setKeysetAlias("file_key") //optional
.setKeysetPrefName("secret_file_shared_prefs") //optional
.build()
@smokelaboratory
smokelaboratory / custom_key.kt
Created March 13, 2020 06:24
JetSec custom key object
val keySpecifications = KeyGenParameterSpec.Builder(
"key_alias",
KeyProperties.PURPOSE_ENCRYPT or KeyProperties.PURPOSE_DECRYPT
).apply {
setKeySize(256)
setBlockModes(KeyProperties.BLOCK_MODE_GCM)
setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_NONE)
}.build()
val masterKey = MasterKeys.getOrCreate(keySpecifications)
Widget getMotionBuilder(MotionElement child, AnimationController animCont,
{bool isExit = false}) {
Animation transAnim;
Widget builder;
switch (child.mode) {
case MotionMode.TRANSLATE_FADE:
transAnim = getTransAnim(child, animCont, isExit);
builder = FadeTransition(
opacity: getOpacAnim(child, animCont, isExit),
@smokelaboratory
smokelaboratory / motion_widget_example.dart
Last active March 7, 2020 14:42
Motion Widget Example
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: <Widget>[
Expanded(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 35, vertical: 50),
child: Motion<Column>(
durationMs: 2500,