Skip to content

Commit

Permalink
Enable android secureId as a password default
Browse files Browse the repository at this point in the history
  • Loading branch information
ptsiogas4 committed May 29, 2019
1 parent ae04f15 commit 3572a0d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/src/main/java/ptsiogas/gr/securestorage/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ class MainActivity : AppCompatActivity() {
setContentView(R.layout.activity_main)
val sampleText = "This is a properly decrypted text."
testTextView.text = sampleText
SecureBoxHelper.instance.encryptString("testVar", sampleText, "mySecurePassword")
SecureBoxHelper.instance.encryptString("testVar", sampleText)

testButton.setOnClickListener {
resultTextView.text = SecureBoxHelper.instance.decryptString("testVar", "mySecurePassword")
resultTextView.text = SecureBoxHelper.instance.decryptString("testVar")
}

wrongPassTestButton.setOnClickListener {
Expand Down
19 changes: 17 additions & 2 deletions securebox/src/main/java/ptsiogas/gr/securebox/SecureBoxHelper.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package ptsiogas.gr.securebox

import android.annotation.SuppressLint
import android.content.Context
import android.os.Build
import android.provider.Settings
import android.util.Log
import java.io.File
import java.io.IOException
Expand All @@ -12,6 +15,9 @@ import javax.crypto.spec.IvParameterSpec
import javax.crypto.spec.PBEKeySpec
import javax.crypto.spec.SecretKeySpec
import java.io.ObjectOutputStream
import android.provider.Settings.Secure



class SecureBoxHelper {
companion object {
Expand Down Expand Up @@ -41,7 +47,7 @@ class SecureBoxHelper {
return true
}

fun encryptString(variableName: String, plainText: String, passwordString: String): Boolean {
fun encryptString(variableName: String, plainText: String, passwordString: String = getSecureId()): Boolean {
if (!checkInit()) {
return false
}
Expand All @@ -60,7 +66,7 @@ class SecureBoxHelper {
return false
}

fun decryptString(variableName: String, passwordString: String): String? {
fun decryptString(variableName: String, passwordString: String = getSecureId()): String? {
if (!checkInit()) {
return null
}
Expand Down Expand Up @@ -210,4 +216,13 @@ class SecureBoxHelper {
return HashMap<String, Boolean>()
}

@SuppressLint("HardwareIds")
private fun getSecureId(): String {
val secureAndroidId = Settings.Secure.getString(this.context?.getContentResolver(), Settings.Secure.ANDROID_ID)
var androidId = "UNKNOWN"
if (secureAndroidId.isNotEmpty()) {
androidId = secureAndroidId
}
return androidId
}
}

0 comments on commit 3572a0d

Please sign in to comment.