@@ -24,6 +24,7 @@ import org.witness.proofmode.notaries.OpenTimestampsNotarizationProvider
24
24
import timber.log.Timber
25
25
import java.io.IOException
26
26
import java.util.concurrent.Executors
27
+ import kotlin.random.Random
27
28
28
29
/* *
29
30
* Created by n8fr8 on 10/10/16.
@@ -41,8 +42,24 @@ class ProofModeApp : MultiDexApplication() {
41
42
var pubKey: String? = null
42
43
try {
43
44
val prefs = PreferenceManager .getDefaultSharedPreferences(this )
44
- pubKey = PgpUtils .getInstance(applicationContext,prefs.getString(PREFS_KEY_PASSPHRASE ,
45
- PREFS_KEY_PASSPHRASE_DEFAULT )).publicKeyFingerprint
45
+
46
+ if (PgpUtils .keyRingExists(this )) {
47
+ pubKey = PgpUtils .getInstance(
48
+ applicationContext, prefs.getString(
49
+ PREFS_KEY_PASSPHRASE ,
50
+ PREFS_KEY_PASSPHRASE_DEFAULT
51
+ )
52
+ ).publicKeyFingerprint
53
+ }
54
+ else
55
+ {
56
+ var newPassPhrase = getRandPassword(12 )
57
+ prefs.edit().putString(PREFS_KEY_PASSPHRASE ,newPassPhrase).commit()
58
+ pubKey = PgpUtils .getInstance(
59
+ applicationContext, newPassPhrase
60
+ ).publicKeyFingerprint
61
+
62
+ }
46
63
47
64
} catch (e: PGPException ) {
48
65
Timber .e(e, " error getting public key" )
@@ -54,6 +71,22 @@ class ProofModeApp : MultiDexApplication() {
54
71
}
55
72
}
56
73
74
+ fun getRandPassword (n : Int ): String
75
+ {
76
+ val characterSet = " 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
77
+
78
+ val random = Random (System .nanoTime())
79
+ val password = StringBuilder ()
80
+
81
+ for (i in 0 until n)
82
+ {
83
+ val rIndex = random.nextInt(characterSet.length)
84
+ password.append(characterSet[rIndex])
85
+ }
86
+
87
+ return password.toString()
88
+ }
89
+
57
90
private fun showToastMessage (message : String ) {
58
91
val handler = Handler (Looper .getMainLooper())
59
92
handler.post {
0 commit comments