{"id":427577,"date":"2024-07-27T15:00:48","date_gmt":"2024-07-27T15:00:48","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=427577"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=427577","title":{"rendered":"<span>PinLockSreen \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 KeyStore. Kotlin. Jetpack Compose<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<h2>\u041d\u0430\u0447\u0430\u043b\u043e<\/h2>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u043b\u044e\u0431\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c\u0441\u044f, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 KeyStore \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u043c\u043e\u0431\u0438\u043b\u044c\u043d\u043e\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438, \u0434\u043b\u044f \u0447\u0435\u0433\u043e \u043d\u0443\u0436\u0435\u043d \u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c \u0435\u0433\u043e \u0432 \u043a\u0440\u0430\u0439\u043d\u0435 \u043b\u0435\u0433\u043a\u043e\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0435. \u0422\u0430\u043a\u0436\u0435 \u043f\u043e\u0433\u0440\u0443\u0437\u0438\u043c\u0441\u044f \u0432 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u044d\u043a\u0440\u0430\u043d\u0430 \u0432\u0445\u043e\u0434\u0430 \u0432 \u0432\u0430\u0448\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435. \u0421\u0442\u0430\u0442\u044c\u044f \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0430 \u043d\u0430 3 \u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0445 \u0440\u0430\u0437\u0434\u0435\u043b\u0430 &#8212; KeyStore, UI \u0438 ViewModel. <\/p>\n<p>\u0426\u0435\u043b\u044c\u044e \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0433\u0430\u0439\u0434\u0430 \u044d\u0442\u043e \u0432\u043e\u0442 \u0442\u0430\u043a\u043e\u0439 \u044d\u043a\u0440\u0430\u043d \u0441 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u043e\u043c:<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/25f\/953\/3a1\/25f9533a14a32ee84f1059b626deb446.png\" width=\"332\" height=\"745\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/25f\/953\/3a1\/25f9533a14a32ee84f1059b626deb446.png\"\/><\/figure>\n<p>P.S. \u0425\u043e\u0447\u0443 \u0441\u0440\u0430\u0437\u0443 \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0434\u0438\u0442\u044c, \u0447\u0442\u043e \u043c\u043e\u0439 \u043a\u043e\u0434 \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0438\u043b\u0438 \u043a\u0430\u043a\u0438\u043c-\u0442\u043e \u0441\u0443\u043f\u0435\u0440 \u043f\u0440\u043e\u0444\u0435\u0441\u0441\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u043c, \u044f \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u0435\u043b\u0430\u043b, \u0442\u043e, \u0447\u0442\u043e \u043c\u043e\u0433, \u0438\u043c\u0435\u043d\u043d\u043e \u043f\u043e\u044d\u0442\u043e\u043c\u0443, \u0435\u0441\u043b\u0438 \u0435\u0441\u0442\u044c \u0436\u0435\u043b\u0430\u043d\u0438\u0435, \u0442\u043e \u0436\u0434\u0443 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0435\u0432 \u0441 \u043f\u043e\u044f\u0441\u043d\u0435\u043d\u0438\u044f\u043c\u0438, \u0433\u0434\u0435 \u044f \u043c\u043e\u0433 \u043b\u0443\u0447\u0448\u0435.<\/p>\n<h2>KeyStore<\/h2>\n<p><a href=\"https:\/\/developer.android.com\/reference\/java\/security\/KeyStore\" rel=\"noopener noreferrer nofollow\">\u0418\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 <\/a>\u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0447\u0443\u0432\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438, \u0442\u0430\u043a\u0438\u043c\u0438, \u043a\u0430\u043a \u043f\u0430\u0440\u043e\u043b\u0438, \u043a\u043b\u044e\u0447\u0438, \u043a\u043e\u0434\u044b \u0438 \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u044b, \u0432 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u043c \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435. \u0414\u0430\u043d\u043d\u044b\u0439 API \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u043c\u043e\u0431\u0438\u043b\u044c\u043d\u043e\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043f\u043e\u0434 Android, \u043d\u043e \u0438 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0430\u0445 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0433\u043e \u043c\u0435\u0441\u0442\u0430 \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0432. \u042f \u043d\u0435 \u0431\u0443\u0434\u0443 \u0443\u0433\u043b\u0443\u0431\u043b\u044f\u0442\u044c\u0441\u044f \u0432 \u043f\u043e\u043d\u044f\u0442\u0438\u0435 KeyStore, \u0442\u0430\u043a \u043a\u0430\u043a \u044d\u0442\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u0442\u0435\u043c\u0430, \u0434\u0430 \u0438 \u043a \u0442\u043e\u043c\u0443 \u0436\u0435 \u0435\u0441\u0442\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0433\u0430\u0439\u0434\u043e\u0432 \u0440\u0430\u0441\u043a\u0440\u044b\u0432\u0430\u044e\u0449\u0438\u0435 \u044d\u0442\u0443 \u0442\u0435\u043c\u0443, \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u043d\u0430 \u0445\u0430\u0431\u0440\u0435 (<a href=\"https:\/\/habr.com\/ru\/articles\/445786\/\" rel=\"noopener noreferrer nofollow\">\u0425\u0430\u0431\u0440 \u0441\u0442\u0430\u0442\u044c\u044f<\/a>, <a href=\"https:\/\/learnitweb.com\/java-security\/a-guide-to-java-keystore-and-keystore-api\/\" rel=\"noopener noreferrer nofollow\">\u0410\u043d\u0433\u043b\u043e\u044f\u0437\u044b\u0447\u043d\u0430\u044f<\/a> \u043e\u0442 EditorialTeam in Java security &#8212; \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0430\u044f). <\/p>\n<p>\u041c\u044b \u0436\u0435 \u0432\u043e\u0437\u044c\u043c\u0435\u043c \u043e\u0442 \u043d\u0435\u0433\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0430\u043c\u043e\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0435, \u0430 \u0442\u043e\u0447\u043d\u0435\u0435 \u043c\u043e\u0434\u0443\u043b\u0438 EncryptedSharedPreferences \u0438 MasterKey.<\/p>\n<p>\u041f\u0435\u0440\u0435\u0434 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c KeyStore \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0435\u0433\u043e \u0437\u0430\u0438\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0438\u0442\u044c \u0432 build.gradle<\/p>\n<pre><code class=\"kotlin\">\/\/ Keystore implementation(\"androidx.security:security-crypto:1.1.0-alpha06\")<\/code><\/pre>\n<pre><code class=\"kotlin\">class KeystoreManager(context: Context) {     private val masterKeyAlias = MasterKey.Builder(context)         .setKeyScheme(MasterKey.KeyScheme.AES256_GCM)         .build()      private val sharedPreferences = EncryptedSharedPreferences.create(         context,         \"encrypted_prefs\",         masterKeyAlias,         EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,         EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM     )      fun savePin(pin: String) {         sharedPreferences.edit().putString(\"pin\", pin).apply()     }      fun getPin(): String? {         return sharedPreferences.getString(\"pin\", null)     } }<\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0442\u0430\u043a\u043e\u0439 \u043a\u043b\u0430\u0441\u0441 \u0434\u043b\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430. \u0412 \u043d\u0430\u0447\u0430\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u043c masterKey. \u041e\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0437\u0430\u0449\u0438\u0442\u044b \u043a\u0430\u043a \u043a\u043b\u044e\u0447\u0435\u0439, \u0442\u0430\u043a \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0432\u043d\u0443\u0442\u0440\u0438 <code>SharedPreference<\/code>. \u0418 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0441\u0445\u0435\u043c\u0443 \u0448\u0438\u0444\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u043b\u044f \u0441\u0430\u043c\u043e\u0433\u043e \u043a\u043b\u044e\u0447\u0430. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f AES-256 \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 GCM (Galois\/Counter Mode). \u042d\u0442\u043e\u0442 \u0440\u0435\u0436\u0438\u043c \u0448\u0438\u0444\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u043a\u043e\u043d\u0444\u0438\u0434\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0438 \u0446\u0435\u043b\u043e\u0441\u0442\u043d\u043e\u0441\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0445, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044e. <br \/>\u0414\u043b\u044f <code>SharedPreference<\/code> \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c EncryptedSharedPreferences. PrefKeyEncryptionScheme \u0441\u0445\u0435\u043c\u0430 \u0448\u0438\u0444\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u043b\u044f \u043a\u043b\u044e\u0447\u0435\u0439 \u0432 <code>SharedPreferences<\/code>, \u0430 PrefValueEncryptionScheme \u0441\u0445\u0435\u043c\u0430 \u0448\u0438\u0444\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u043b\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0432 <code>SharedPreferences<\/code>.  <br \/>\u0418 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0441\u0430\u043c\u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u043f\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044e \u043f\u0438\u043d\u0430 \u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044e \u0435\u0433\u043e.<\/p>\n<p>\u042f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043b\u0438 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u043c \u043c\u0435\u0442\u043e\u0434 getPin()? \u0414\u0430. \u041f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0441 \u0443\u0436\u0435 \u0437\u0430\u0448\u0438\u0444\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c sharedprefs \u0438 \u0434\u0435\u0448\u0438\u0444\u0440\u0443\u0435\u0442\u0441\u044f \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430. \u041f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c, \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0441\u043b\u0438 \u0432\u044b \u043d\u0435 \u0440\u0435\u0448\u0438\u0442\u0435 \u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043b\u043e\u0433 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c \u043f\u0438\u043d\u043e\u043c.<\/p>\n<h2>\u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0430 UI<\/h2>\n<p>\u041e\u0442\u0447\u0430\u0441\u0442\u0438 \u0438\u043c\u0435\u043d\u043d\u043e \u0438\u0437-\u0437\u0430 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043d\u0438\u0433\u0434\u0435 \u0432 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0435 \u043d\u0435\u0442 \u0431\u043e\u043b\u0435\u0435 \u0443\u0434\u043e\u0431\u043d\u044b\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u0434\u043b\u044f PinLockScreen \u0441 JetpackCompose \u044f \u0440\u0435\u0448\u0438\u043b \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u0435\u043d\u044c\u043a\u0438\u0439 \u0433\u0430\u0439\u0434, \u0434\u043b\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0441\u0432\u043e\u0438\u0445 \u0437\u043d\u0430\u043d\u0438\u0439 \u0438, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043f\u043e\u043c\u043e\u0449\u0438 \u0434\u0440\u0443\u0433\u0438\u043c. \u041a \u0441\u043b\u043e\u0432\u0443, \u0435\u0441\u0442\u044c <a href=\"https:\/\/github.com\/raheemadamboev\/pin-lock-compose\" rel=\"noopener noreferrer nofollow\">\u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 <\/a>\u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u043e\u0440\u0430\u0445 \u0433\u0438\u0442\u0445\u0430\u0431\u0430, \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u044e\u0449\u0430\u044f UI \u043f\u0438\u043d\u043b\u043e\u043a\u0430 (\u0431\u0435\u0437 \u043a\u0430\u043a\u043e\u0439-\u043b\u0438\u0431\u043e \u043b\u043e\u0433\u0438\u043a\u0438 \u0437\u0430\u0449\u0438\u0442\u044b), \u043e\u0434\u043d\u0430\u043a\u043e, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u0434\u043b\u044f \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u0435\u043d\u0438\u044f \u043b\u0435\u0433\u043a\u0438\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u0440\u0430\u0439\u043d\u0435 \u043d\u0435\u0436\u0435\u043b\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c.<\/p>\n<p>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0446\u0432\u0435\u0442\u043e\u0432 \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u0446\u0432\u0435\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f \u043f\u0440\u043e\u043f\u0438\u0441\u0430\u043b \u0432 Theme, \u0441\u0434\u0435\u043b\u0430\u043d\u043e \u044d\u0442\u043e \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0442\u0435\u043c\u043d\u0443\u044e \u0438 \u0441\u0432\u0435\u0442\u043b\u0443\u044e \u0442\u0435\u043c\u0443, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043b\u044e\u0431\u044b\u0435 \u0446\u0432\u0435\u0442\u0430.<\/p>\n<p> \u0414\u0430\u043b\u0435\u0435 \u0446\u0432\u0435\u0442\u0430 \u0432 \u043c\u043e\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f \u0442\u0430\u043a:<\/p>\n<pre><code class=\"kotlin\">MaterialTheme.colorScheme.tertiary<\/code><\/pre>\n<p>\u0421\u0430\u043c\u043e\u0435 \u0433\u043b\u0430\u0432\u043d\u043e\u0435 \u0432 \u043f\u0438\u043d\u043b\u043e\u043a\u0435 \u044d\u0442\u043e \u043a\u043b\u0430\u0432\u0438\u0430\u0442\u0443\u0440\u0430, \u0430 \u043e\u043d\u0430 \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u043a\u043d\u043e\u043f\u043e\u043a, \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u043a\u043d\u043e\u043f\u043a\u0443, \u0432 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0431\u0443\u0434\u0435\u043c \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c content \u0441 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0435\u0439 Composable, \u0442\u043a \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430 \u0431\u0443\u0434\u0435\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 Text().<\/p>\n<pre><code>@Composable private fun KeyButton(     onClick: () -&gt; Unit,     shape: Shape = RoundedCornerShape(100),     content: @Composable () -&gt; Unit ) {     Box(         modifier = Modifier             .padding(8.dp)             .clip(shape)             .background(                 color = MaterialTheme.colorScheme.tertiary,                 shape = RoundedCornerShape(100)             )             .clickable(onClick = onClick)             .defaultMinSize(minWidth = 95.dp, minHeight = 95.dp)             .padding(4.dp),         contentAlignment = Alignment.Center     ) {         CompositionLocalProvider(LocalContentColor provides MaterialTheme.colorScheme.secondary) {             content()         }     } }<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0441\u0430\u043c\u0430 \u043a\u043b\u0430\u0432\u0438\u0430\u0442\u0443\u0440\u0430, \u044f \u043d\u0435 \u0434\u043e\u0434\u0443\u043c\u0430\u043b\u0441\u044f \u043d\u0438 \u0434\u043e \u0447\u0435\u0433\u043e \u043a\u0440\u043e\u043c\u0435 \u043a\u0430\u043a \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043a\u043b\u0430\u0432\u0438\u0430\u0442\u0443\u0440\u0443 \u0432 \u0432\u0438\u0434\u0435 \u0441\u043f\u0438\u0441\u043a\u0430 \u0438\u0437 \u0441\u043f\u0438\u0441\u043a\u043e\u0432 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0440\u044f\u0434\u0430 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432. \u0414\u0430\u043d\u043d\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0443\u0447\u0435\u0431\u043d\u044b\u043c, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u043d\u0435 \u0432\u044b\u043d\u043e\u0448\u0443 \u0441\u0442\u0440\u043e\u043a\u0438 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u044b. \u0415\u0441\u043b\u0438 \u0432\u044b \u0434\u0435\u043b\u0430\u0435\u0442\u0435 \u0441\u0432\u043e\u0439 \u043f\u0440\u043e\u0435\u043a\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0437\u0432\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0438\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 \u044d\u0442\u043e \u0432 \u043a\u043e\u043c\u043c\u0435\u0440\u0446\u0438\u0438, \u0442\u043e \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0432\u0441\u0435 \u044d\u0442\u043e \u043f\u0435\u0440\u0435\u043d\u0435\u0441\u0442\u0438 \u0432 \u0440\u0435\u0441\u0443\u0440\u0441\u044b, \u0430 \u0441\u0430\u043c \u0441\u043f\u0438\u0441\u043e\u043a \u043a\u043d\u043e\u043f\u043e\u043a \u0432\u044b\u043d\u0435\u0441\u0442\u0438 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0438\u043b\u0438 \u0436\u0435 \u043a\u043b\u0430\u0441\u0441.<\/p>\n<pre><code class=\"kotlin\">@Composable private fun Keyboard( ) {     val listKeys = listOf(         listOf(\"1\", \"2\", \"3\"),         listOf(\"4\", \"5\", \"6\"),         listOf(\"7\", \"8\", \"9\"),         listOf(\"del\", \"0\", \"OK\")     )      Column(         modifier = Modifier             .background(color = MaterialTheme.colorScheme.background)             .fillMaxSize()             .padding(bottom = 100.dp),         verticalArrangement = Arrangement.Bottom,         horizontalAlignment = Alignment.CenterHorizontally,     ) {         Spacer(modifier = Modifier.height(100.dp))          listKeys.forEach { rows -&gt;             Row {                 rows.forEach {                     KeyButton(                         onClick = {                                                     }                     ) {                         when (it) {                             \"del\" -&gt; {                                 Icon(                                     painter = painterResource(id = R.drawable.del_icon),                                     contentDescription = \"Clear\",                                     modifier = Modifier                                         .size(30.dp),                                     tint = MaterialTheme.colorScheme.secondary                                 )                             }                              \"OK\" -&gt; {                                 Icon(                                     imageVector = Icons.Default.Check,                                     contentDescription = \"Success\",                                     modifier = Modifier                                         .size(35.dp),                                     tint = MaterialTheme.colorScheme.secondary                                 )                             }                              else -&gt; Text(                                 text = it,                                 fontSize = 30.sp,                                 fontWeight = FontWeight.Medium,                                 color = MaterialTheme.colorScheme.secondary                             )                         }                     }                 }             }         }     } }<\/code><\/pre>\n<p>Column \u0432\u043d\u0443\u0442\u0440\u0438, \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043f\u0440\u043e\u0445\u043e\u0436\u0443\u0441\u044c \u043f\u043e \u0441\u043f\u0438\u0441\u043a\u0443, \u043e\u0431\u0440\u0430\u0437\u0443\u044f \u0442\u0435\u043c \u0441\u0430\u043c\u044b\u043c rows, \u043e\u043d\u0438 \u0438 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0440\u044f\u0434\u0430\u043c\u0438 \u0441 \u043a\u043d\u043e\u043f\u043a\u0430\u043c\u0438. \u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0432 \u0441\u0442\u043e\u043b\u0431\u0446\u0435 \u0441\u043f\u0435\u0446\u0441\u0438\u043c\u0432\u043e\u043b \u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0441\u044c \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435\u043c when, \u0432 \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u043d\u0435 \u043a\u043d\u043e\u043f\u043a\u0430 \u041e\u041a \u0438\u043b\u0438 \u0443\u0434\u0430\u043b\u0438\u0442\u044c, \u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u043f\u0438\u0441\u044b\u0432\u0430\u044e \u0432 \u043a\u043e\u043d\u0442\u0435\u043d\u0442 \u043a\u043d\u043e\u043f\u043a\u0438 \u0442\u0435\u043a\u0441\u0442.<br \/>\u0414\u0430\u043b\u0435\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0432\u043e\u0442 \u0442\u0430\u043a\u0438\u0435 \u0442\u043e\u0447\u043a\u0438 \u0434\u043b\u044f \u0432\u0432\u043e\u0434\u0430 \u0438 \u0442\u0435\u043a\u0441\u0442<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/4e0\/f45\/9d2\/4e0f459d26da029eb4eff520cea679c0.png\" width=\"241\" height=\"106\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/4e0\/f45\/9d2\/4e0f459d26da029eb4eff520cea679c0.png\"\/><\/figure>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0434\u0432\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 &#8212; \u0442\u0435\u043a\u0441\u0442 \u0438 \u0441\u0430\u043c\u0438 \u0442\u043e\u0447\u043a\u0438<\/p>\n<pre><code class=\"kotlin\">@Composable private fun PinDot(isFilled: Boolean) {     Box(         modifier = Modifier             .padding(10.dp)             .size(30.dp)             .background(                 if (isFilled) MaterialTheme.colorScheme.tertiary else                     if (isSystemInDarkTheme()) White                     else Color.Gray, CircleShape             )     ) }<\/code><\/pre>\n<p>\u0412 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u044e isFilled \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0442\u043e\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c, \u043a\u0430\u043a \u0444\u043b\u0430\u0433 \u0434\u043b\u044f \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043f\u0440\u0438 \u0432\u0432\u043e\u0434\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u0430.<\/p>\n<h2>ViewModel<\/h2>\n<p>\u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c \u0442\u0435\u043a\u0441\u0442 \u0432\u0432\u043e\u0434\u0430 \u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442\u044c \u043f\u043e\u00a0\u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u0438 \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0432\u044c\u044e\u043c\u043e\u0434\u0435\u043b\u044c\u043a\u0443, \u0432\u00a0\u043d\u0435\u0439 \u0431\u0443\u0434\u0435\u0442 \u043e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u043b\u043e\u0433\u0438\u043a\u0430 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439, \u0432\u00a0\u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u043f\u0430\u0440\u043e\u043b\u044f \u0432\u00a0KeyStore.<br \/>\u0414\u043b\u044f\u00a0\u0441\u0430\u043c\u043e\u0439 ViewModel \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u043c\u043e\u0434\u0435\u043b\u044c state. \u0418 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0441\u00a0events, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u044b \u043a\u0430\u043a\u00a0\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0432\u00a0\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438.<\/p>\n<pre><code class=\"kotlin\">data class PinLockState(     val isAuthenticated: Boolean = false,     val inputPin: String = \"\",     val error: ErrorPin? = null,     val confirmPin: String? = null )  sealed interface PinLockEvent {      data class AddDigit(val digit: String) : PinLockEvent     data object DeleteDigit : PinLockEvent     data object ClearPin : PinLockEvent     data object CheckPin : PinLockEvent  }<\/code><\/pre>\n<p>\u0412 \u0441\u0442\u0435\u0439\u0442\u0435 \u043b\u0435\u0436\u0438\u0442 \u0444\u043b\u0430\u0436\u043e\u043a isAuthenticated \u0434\u043b\u044f\u00a0\u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c, \u0435\u0441\u0442\u044c\u00a0\u043b\u0438 \u0443\u00a0\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0443\u0436\u0435 \u043f\u0438\u043d\u043a\u043e\u0434 \u0438\u043b\u0438\u00a0\u043d\u0435\u0442, inputPin\u00a0\u2014 \u0441\u0430\u043c \u043f\u0438\u043d\u043a\u043e\u0434, \u043a\u0443\u0434\u0430 \u0431\u0443\u0434\u0443\u0442 \u0432\u0445\u043e\u0434\u0438\u0442\u044c \u0432\u0432\u043e\u0434\u0438\u043c\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, error\u00a0\u2014 \u043e\u0448\u0438\u0431\u043a\u0438, \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u0442\u0430\u043a\u0436\u0435 \u0432\u00a0\u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0444\u043b\u0430\u0433\u0430, \u0434\u043b\u044f\u00a0\u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0432\u0445\u043e\u0434\u0430, confirmPin\u00a0\u2014 \u0442\u043e\u0436\u0435 \u043f\u0438\u043d\u043a\u043e\u0434, \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0443\u0436\u0435\u043d \u0434\u043b\u044f\u00a0\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u0438 \u0442\u043e\u043b\u044c\u043a\u043e.<\/p>\n<p>\u0421\u0430\u043c\u0430 ViewModel \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0430 \u043d\u0438\u0436\u0435.<\/p>\n<pre><code class=\"kotlin\">class PinLockViewModel(     private val keystoreManager: KeystoreManager ) : ViewModel() {      private val _state = MutableStateFlow(PinLockState())     val state: StateFlow&lt;PinLockState&gt; = _state      init {         val pinSet = keystoreManager.getPin().isNullOrBlank()         _state.update {             it.copy(                 isAuthenticated = !pinSet             )         }     }      fun onEvent(event: PinLockEvent) {         when (event) {             is PinLockEvent.DeleteDigit -&gt; {                 _state.update {                     it.copy(                         inputPin = it.inputPin.substring(0, it.inputPin.length - 1)                     )                 }             }             is PinLockEvent.AddDigit -&gt; {                 _state.update {                     it.copy(                         inputPin = it.inputPin.plus(event.digit)                     )                 }             }             is PinLockEvent.ClearPin -&gt; {                 _state.update {                     it.copy(                         inputPin = \"\"                     )                 }             }             is PinLockEvent.CheckPin -&gt; {                 val currentState = _state.value                 if (currentState.inputPin.length == 4) {                     if (currentState.isAuthenticated) {                         val storedPin = keystoreManager.getPin()                         if (currentState.inputPin == storedPin) {                             _state.update {                                 it.copy(                                     error = ErrorPin.SUCCESS                                 )                             }                         } else {                             _state.update {                                 it.copy(                                     error = ErrorPin.INCORRECT_PASS                                 )                             }                              onEvent(PinLockEvent.ClearPin)                         }                     } else {                         if (currentState.confirmPin.isNullOrBlank()) {                             _state.update {                                 it.copy(                                     confirmPin = currentState.inputPin,                                     error = ErrorPin.TRY_PIN                                 )                             }                             onEvent(PinLockEvent.ClearPin)                         } else {                             if (currentState.inputPin == currentState.confirmPin) {                                 keystoreManager.savePin(currentState.inputPin)                                 _state.value = currentState.copy(                                     isAuthenticated = true,                                     error = ErrorPin.SUCCESS,                                     confirmPin = null                                 )                             } else {                                 _state.value = currentState.copy(error = ErrorPin.INCORRECT_PASS, confirmPin = null)                                 onEvent(PinLockEvent.ClearPin)                             }                         }                     }                 } else {                     _state.value = currentState.copy(error = ErrorPin.NOT_ENOUGH_DIG)                     onEvent(PinLockEvent.ClearPin)                 }             }         }     }   }  enum class ErrorPin(val error: Int){     SUCCESS(0),     INCORRECT_PASS(1),     NOT_ENOUGH_DIG(2),     TRY_PIN(3) } <\/code><\/pre>\n<p>\u0412 \u043d\u0430\u0447\u0430\u043b\u0435 \u043e\u0433\u043b\u0430\u0448\u0430\u0435\u043c StateFlow \u0434\u043b\u044f\u00a0\u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u0432\u00a0\u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 init \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u043c \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044e, \u0435\u0441\u0442\u044c\u00a0\u043b\u0438 \u0432\u043e\u043e\u0431\u0449\u0435 \u0443\u00a0\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043f\u0430\u0440\u043e\u043b\u044c \u0438\u043b\u0438\u00a0\u043d\u0435\u0442. \u0414\u0430\u043b\u0435\u0435 \u044d\u0442\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f (onEvent). \u0422\u0443\u0442 \u0432\u0441\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043a\u0440\u043e\u043c\u0435 \u043a\u0430\u043a\u00a0CheckPin, \u043d\u043e\u00a0\u0438 \u0442\u0430\u043c \u0442\u043e\u0436\u0435 \u0432\u0441\u0435 \u043f\u0440\u043e\u0441\u0442\u043e, \u0435\u0441\u043b\u0438 \u0443\u0433\u043b\u0443\u0431\u0438\u0442\u044c\u0441\u044f, \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0438\u0434\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043d\u0430\u00a0\u043a\u043e\u043b\u2011\u0432\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432, \u0435\u0441\u043b\u0438 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 \u0442\u043e \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043e\u0448\u0438\u0431\u043a\u0430 \u0438 \u043f\u0438\u043d \u0441\u0442\u0438\u0440\u0430\u0435\u0442\u0441\u044f, \u0434\u0430\u043b\u0435\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043d\u0430\u00a0\u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044e, \u0435\u0441\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043d\u0435\u00a0\u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d, \u0442\u043e \u0438\u0434\u0435\u0442 \u043b\u043e\u0433\u0438\u043a\u0430 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u043f\u0438\u043d\u0430 \u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0432\u00a0KeyStore, \u0435\u0441\u043b\u0438 \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d, \u0442\u043e \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0441\u00a0\u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c\u0438 errors, \u043a\u0441\u0442\u0430\u0442\u0438, \u043f\u0440\u043e\u00a0\u043d\u0438\u0445, \u0441\u043e\u0437\u0434\u0430\u043b \u0435\u043d\u0443\u043c \u043a\u043b\u0430\u0441\u0441 \u0434\u043b\u044f\u00a0\u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u043e\u0448\u0438\u0431\u043a\u0438 .<\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043b\u0438\u0448\u044c \u0441\u043e\u0435\u0434\u0438\u043d\u0438\u0442\u044c \u044d\u0442\u043e \u0441 UI, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043e \u043d\u0438\u0436\u0435.<\/p>\n<pre><code class=\"kotlin\">@Composable fun PinLockScreen(     navController: NavController,     viewModel: PinLockViewModel ) {     val statePin by viewModel.state.collectAsState()     LaunchedEffect(statePin.isAuthenticated, statePin.error) {         if (statePin.isAuthenticated &amp;&amp; statePin.error == ErrorPin.SUCCESS) {             navController.popBackStack()             navController.navigate(\"mainScreen\")         }     }     Keyboard(         onEvent = viewModel::onEvent,         statePin = statePin     ) }   @Composable private fun Keyboard(     onEvent: (PinLockEvent) -&gt; Unit,     statePin: PinLockState ) {     val listKeys = listOf(         listOf(\"1\", \"2\", \"3\"),         listOf(\"4\", \"5\", \"6\"),         listOf(\"7\", \"8\", \"9\"),         listOf(\"del\", \"0\", \"OK\")     )      Column(         modifier = Modifier             .background(color = MaterialTheme.colorScheme.background)             .fillMaxSize()             .padding(bottom = 100.dp),         verticalArrangement = Arrangement.Bottom,         horizontalAlignment = Alignment.CenterHorizontally,     ) {         var text = when(statePin.error) {             ErrorPin.INCORRECT_PASS -&gt; \"\u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0439\u0442\u0435 \u0435\u0449\u0451 \u0440\u0430\u0437\"             ErrorPin.TRY_PIN -&gt; \"\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u043f\u0438\u043d-\u043a\u043e\u0434 \u0435\u0449\u0451 \u0440\u0430\u0437 \u0434\u043b\u044f \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f\"             ErrorPin.NOT_ENOUGH_DIG -&gt; \"\u041d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0446\u0438\u0444\u0440, \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0439\u0442\u0435 \u0435\u0449\u0435 \u0440\u0430\u0437\"             else -&gt; \"\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u043f\u0438\u043d-\u043a\u043e\u0434\"         }         if (!statePin.isAuthenticated &amp;&amp; statePin.error == null) {             text = \"\u0414\u043b\u044f \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438  \u0432\u0432\u0435\u0434\u0438\u0442\u0435 \u043f\u0438\u043d-\u043a\u043e\u0434\"         }         Text(             text = text,             fontSize = 18.sp,             textAlign = TextAlign.Center,             color = MaterialTheme.colorScheme.secondary         )         Spacer(modifier = Modifier.height(30.dp))         Row(             modifier = Modifier.fillMaxWidth(),             horizontalArrangement = Arrangement.Center,             verticalAlignment = Alignment.CenterVertically,         ) {             repeat(4) { index -&gt;                 val isFilled = index &lt; statePin.inputPin.length                 PinDot(isFilled = isFilled)             }         }          Spacer(modifier = Modifier.height(100.dp))          listKeys.forEach { rows -&gt;             Row {                 rows.forEach {                     KeyButton(                         onClick = {                             when (it) {                                 \"del\" -&gt; if (statePin.inputPin.isNotEmpty()) onEvent(PinLockEvent.DeleteDigit)                                 \"OK\" -&gt; {                                     onEvent(PinLockEvent.CheckPin)                                 }                                 else -&gt; {                                     if (statePin.inputPin.length &lt; 4) onEvent(                                         PinLockEvent.AddDigit(it)                                     )                                 }                             }                         }                     ) {                         when (it) {                             \"del\" -&gt; {                                 Icon(                                     painter = painterResource(id = R.drawable.del_icon),                                     contentDescription = \"Clear\",                                     modifier = Modifier                                         .size(30.dp),                                     tint = MaterialTheme.colorScheme.secondary                                 )                             }                              \"OK\" -&gt; {                                 Icon(                                     imageVector = Icons.Default.Check,                                     contentDescription = \"Success\",                                     modifier = Modifier                                         .size(35.dp),                                     tint = MaterialTheme.colorScheme.secondary                                 )                             }                              else -&gt; Text(                                 text = it,                                 fontSize = 30.sp,                                 fontWeight = FontWeight.Medium,                                 color = MaterialTheme.colorScheme.secondary                             )                         }                     }                 }             }         }     } }<\/code><\/pre>\n<p>\u0414\u043b\u044f \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u0441\u0442\u0440\u0430\u043d\u0438\u0447\u043a\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u0434\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u0432 \u0441\u0430\u043c\u043e\u043c \u043d\u0430\u0447\u0430\u043b\u0435, \u043e\u043d \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0444\u043b\u0430\u0433\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043b \u0432 \u0441\u0442\u0435\u0439\u0442\u0435.<\/p>\n<pre><code class=\"kotlin\">LaunchedEffect(statePin.isAuthenticated, statePin.error) {         if (statePin.isAuthenticated &amp;&amp; statePin.error == ErrorPin.SUCCESS) {             navController.popBackStack()             navController.navigate(\"mainScreen\")         }     }<\/code><\/pre>\n<p>\u0422\u0435\u043a\u0441\u0442 \u043d\u0430\u0434 \u0442\u043e\u0447\u043a\u0430\u043c\u0438 \u0432\u0432\u043e\u0434\u0430, \u0442\u0430\u043a\u0436\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u043e\u0442 \u0441\u0442\u0435\u0439\u0442\u0430.<\/p>\n<pre><code class=\"kotlin\">var text = when(statePin.error) {             ErrorPin.INCORRECT_PASS -&gt; \"\u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0439\u0442\u0435 \u0435\u0449\u0451 \u0440\u0430\u0437\"             ErrorPin.TRY_PIN -&gt; \"\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u043f\u0438\u043d-\u043a\u043e\u0434 \u0435\u0449\u0451 \u0440\u0430\u0437 \u0434\u043b\u044f \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f\"             ErrorPin.NOT_ENOUGH_DIG -&gt; \"\u041d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0446\u0438\u0444\u0440, \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0439\u0442\u0435 \u0435\u0449\u0435 \u0440\u0430\u0437\"             else -&gt; \"\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u043f\u0438\u043d-\u043a\u043e\u0434\"         }         if (!statePin.isAuthenticated &amp;&amp; statePin.error == null) {             text = \"\u0414\u043b\u044f \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438  \u0432\u0432\u0435\u0434\u0438\u0442\u0435 \u043f\u0438\u043d-\u043a\u043e\u0434\"         }<\/code><\/pre>\n<p>\u0412 MainActivity \u044d\u0442\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0432\u043e\u0442 \u0442\u0430\u043a. \u0414\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u0438 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u043c\u043e\u0434\u0443\u043b\u044c \u0432 build.gradle.<\/p>\n<pre><code class=\"kotlin\">class MainActivity : ComponentActivity() {      private val keystoreManager: KeystoreManager by lazy {         KeystoreManager(applicationContext)     }       private val viewModelPinLock by viewModels&lt;PinLockViewModel&gt;(factoryProducer = {         object : ViewModelProvider.Factory {             override fun &lt;T : ViewModel&gt; create(modelClass: Class&lt;T&gt;): T {                 return PinLockViewModel(keystoreManager) as T             }         }     })      override fun onCreate(savedInstanceState: Bundle?) {         super.onCreate(savedInstanceState)          setContent {             PassManagerTheme {                 val stateItem by viewModelItem.state.collectAsState()                 val navController = rememberNavController()                 NavHost(navController = navController, startDestination = \"auth\") {                     composable(\"auth\") {                         PinLockScreen(                             navController = navController,                             viewModel = viewModelPinLock                         )                     }                     composable(\"mainScreen\") {                         ItemScreen()                     }                  }              }         }     } }<\/code><\/pre>\n<h2>\u0418\u0442\u043e\u0433<\/h2>\n<p>\u0412\u00a0\u0446\u0435\u043b\u043e\u043c, \u044f \u0434\u043e\u0432\u043e\u043b\u0435\u043d \u0438\u0442\u043e\u0433\u043e\u043c, \u0447\u0442\u043e\u00a0\u044f \u043f\u0440\u0438\u043e\u0431\u0440\u0435\u043b \u043d\u043e\u0432\u044b\u0435 \u0437\u043d\u0430\u043d\u0438\u044f \u0438 \u0441\u0434\u0435\u043b\u0430\u043b \u0441\u0432\u043e\u044e \u043b\u043e\u0433\u0438\u043a\u0443 (\u043d\u0435 \u0431\u0435\u0437\u00a0\u0433\u0440\u0435\u0445\u043e\u0432). \u0414\u0430\u043d\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u00a0\u043f\u0435\u0440\u0432\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0441\u043a\u043e\u043f\u0438\u0449\u0435\u043c \u043c\u043e\u0438\u0445 \u0432\u044b\u0432\u043e\u0434\u043e\u0432 \u0434\u043b\u044f\u00a0\u0441\u0430\u043c\u043e\u0433\u043e\u00a0\u0436\u0435 \u0441\u0435\u0431\u044f, \u0445\u043e\u0442\u044f, \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u0441\u0442\u0430\u043d\u0435\u0442 \u043a\u043e\u043c\u0443\u2011\u0442\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u0438\u043b\u0438\u00a0\u0434\u0430\u0436\u0435 \u043f\u043e\u043b\u0435\u0437\u043d\u043e, \u0442\u043e \u0431\u0443\u0434\u0443 \u0440\u0430\u0434.<\/p>\n<p>\u0423\u00a0\u043c\u0435\u043d\u044f \u0435\u0441\u0442\u044c <a href=\"https:\/\/github.com\/v0nd1\" rel=\"noopener noreferrer nofollow\">github<\/a>, \u0442\u0430\u043c \u044f \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u043b <a href=\"https:\/\/github.com\/v0nd1\/PassManager\" rel=\"noopener noreferrer nofollow\">\u043f\u0435\u0442 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435<\/a> \u0441\u00a0\u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435\u043c \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u0438\u043d\u043b\u043e\u043a\u0430. \u0422\u0430\u043a\u0436\u0435, \u0435\u0441\u043b\u0438 \u0432\u0434\u0440\u0443\u0433 \u0447\u0442\u043e\u2011\u0442\u043e\u00a0\u0431\u044b\u043b\u043e \u043d\u0435\u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0442\u043e \u043c\u043e\u0436\u0435\u0442\u0435 \u0437\u0430\u0439\u0442\u0438 \u0438 \u0441\u0430\u043c\u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/831914\/\"> https:\/\/habr.com\/ru\/articles\/831914\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<h2>\u041d\u0430\u0447\u0430\u043b\u043e<\/h2>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u043b\u044e\u0431\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c\u0441\u044f, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 KeyStore \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u043c\u043e\u0431\u0438\u043b\u044c\u043d\u043e\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438, \u0434\u043b\u044f \u0447\u0435\u0433\u043e \u043d\u0443\u0436\u0435\u043d \u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c \u0435\u0433\u043e \u0432 \u043a\u0440\u0430\u0439\u043d\u0435 \u043b\u0435\u0433\u043a\u043e\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0435. \u0422\u0430\u043a\u0436\u0435 \u043f\u043e\u0433\u0440\u0443\u0437\u0438\u043c\u0441\u044f \u0432 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u044d\u043a\u0440\u0430\u043d\u0430 \u0432\u0445\u043e\u0434\u0430 \u0432 \u0432\u0430\u0448\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435. \u0421\u0442\u0430\u0442\u044c\u044f \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0430 \u043d\u0430 3 \u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0445 \u0440\u0430\u0437\u0434\u0435\u043b\u0430 &#8212; KeyStore, UI \u0438 ViewModel. <\/p>\n<p>\u0426\u0435\u043b\u044c\u044e \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0433\u0430\u0439\u0434\u0430 \u044d\u0442\u043e \u0432\u043e\u0442 \u0442\u0430\u043a\u043e\u0439 \u044d\u043a\u0440\u0430\u043d \u0441 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u043e\u043c:<\/p>\n<figure class=\"\"><\/figure>\n<p>P.S. \u0425\u043e\u0447\u0443 \u0441\u0440\u0430\u0437\u0443 \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0434\u0438\u0442\u044c, \u0447\u0442\u043e \u043c\u043e\u0439 \u043a\u043e\u0434 \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0438\u043b\u0438 \u043a\u0430\u043a\u0438\u043c-\u0442\u043e \u0441\u0443\u043f\u0435\u0440 \u043f\u0440\u043e\u0444\u0435\u0441\u0441\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u043c, \u044f \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u0435\u043b\u0430\u043b, \u0442\u043e, \u0447\u0442\u043e \u043c\u043e\u0433, \u0438\u043c\u0435\u043d\u043d\u043e \u043f\u043e\u044d\u0442\u043e\u043c\u0443, \u0435\u0441\u043b\u0438 \u0435\u0441\u0442\u044c \u0436\u0435\u043b\u0430\u043d\u0438\u0435, \u0442\u043e \u0436\u0434\u0443 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0435\u0432 \u0441 \u043f\u043e\u044f\u0441\u043d\u0435\u043d\u0438\u044f\u043c\u0438, \u0433\u0434\u0435 \u044f \u043c\u043e\u0433 \u043b\u0443\u0447\u0448\u0435.<\/p>\n<h2>KeyStore<\/h2>\n<p><a href=\"https:\/\/developer.android.com\/reference\/java\/security\/KeyStore\" rel=\"noopener noreferrer nofollow\">\u0418\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 <\/a>\u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0447\u0443\u0432\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438, \u0442\u0430\u043a\u0438\u043c\u0438, \u043a\u0430\u043a \u043f\u0430\u0440\u043e\u043b\u0438, \u043a\u043b\u044e\u0447\u0438, \u043a\u043e\u0434\u044b \u0438 \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u044b, \u0432 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u043c \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435. \u0414\u0430\u043d\u043d\u044b\u0439 API \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u043c\u043e\u0431\u0438\u043b\u044c\u043d\u043e\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043f\u043e\u0434 Android, \u043d\u043e \u0438 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0430\u0445 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0433\u043e \u043c\u0435\u0441\u0442\u0430 \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0432. \u042f \u043d\u0435 \u0431\u0443\u0434\u0443 \u0443\u0433\u043b\u0443\u0431\u043b\u044f\u0442\u044c\u0441\u044f \u0432 \u043f\u043e\u043d\u044f\u0442\u0438\u0435 KeyStore, \u0442\u0430\u043a \u043a\u0430\u043a \u044d\u0442\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u0442\u0435\u043c\u0430, \u0434\u0430 \u0438 \u043a \u0442\u043e\u043c\u0443 \u0436\u0435 \u0435\u0441\u0442\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0433\u0430\u0439\u0434\u043e\u0432 \u0440\u0430\u0441\u043a\u0440\u044b\u0432\u0430\u044e\u0449\u0438\u0435 \u044d\u0442\u0443 \u0442\u0435\u043c\u0443, \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u043d\u0430 \u0445\u0430\u0431\u0440\u0435 (<a href=\"https:\/\/habr.com\/ru\/articles\/445786\/\" rel=\"noopener noreferrer nofollow\">\u0425\u0430\u0431\u0440 \u0441\u0442\u0430\u0442\u044c\u044f<\/a>, <a href=\"https:\/\/learnitweb.com\/java-security\/a-guide-to-java-keystore-and-keystore-api\/\" rel=\"noopener noreferrer nofollow\">\u0410\u043d\u0433\u043b\u043e\u044f\u0437\u044b\u0447\u043d\u0430\u044f<\/a> \u043e\u0442 EditorialTeam in Java security &#8212; \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0430\u044f). <\/p>\n<p>\u041c\u044b \u0436\u0435 \u0432\u043e\u0437\u044c\u043c\u0435\u043c \u043e\u0442 \u043d\u0435\u0433\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0430\u043c\u043e\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0435, \u0430 \u0442\u043e\u0447\u043d\u0435\u0435 \u043c\u043e\u0434\u0443\u043b\u0438 EncryptedSharedPreferences \u0438 MasterKey.<\/p>\n<p>\u041f\u0435\u0440\u0435\u0434 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c KeyStore \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0435\u0433\u043e \u0437\u0430\u0438\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0438\u0442\u044c \u0432 build.gradle<\/p>\n<pre><code class=\"kotlin\">\/\/ Keystore implementation(\"androidx.security:security-crypto:1.1.0-alpha06\")<\/code><\/pre>\n<pre><code class=\"kotlin\">class KeystoreManager(context: Context) {     private val masterKeyAlias = MasterKey.Builder(context)         .setKeyScheme(MasterKey.KeyScheme.AES256_GCM)         .build()      private val sharedPreferences = EncryptedSharedPreferences.create(         context,         \"encrypted_prefs\",         masterKeyAlias,         EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,         EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM     )      fun savePin(pin: String) {         sharedPreferences.edit().putString(\"pin\", pin).apply()     }      fun getPin(): String? {         return sharedPreferences.getString(\"pin\", null)     } }<\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0442\u0430\u043a\u043e\u0439 \u043a\u043b\u0430\u0441\u0441 \u0434\u043b\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430. \u0412 \u043d\u0430\u0447\u0430\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u043c masterKey. \u041e\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0437\u0430\u0449\u0438\u0442\u044b \u043a\u0430\u043a \u043a\u043b\u044e\u0447\u0435\u0439, \u0442\u0430\u043a \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0432\u043d\u0443\u0442\u0440\u0438 <code>SharedPreference<\/code>. \u0418 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0441\u0445\u0435\u043c\u0443 \u0448\u0438\u0444\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u043b\u044f \u0441\u0430\u043c\u043e\u0433\u043e \u043a\u043b\u044e\u0447\u0430. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f AES-256 \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 GCM (Galois\/Counter Mode). \u042d\u0442\u043e\u0442 \u0440\u0435\u0436\u0438\u043c \u0448\u0438\u0444\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u043a\u043e\u043d\u0444\u0438\u0434\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0438 \u0446\u0435\u043b\u043e\u0441\u0442\u043d\u043e\u0441\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0445, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044e. <br \/>\u0414\u043b\u044f <code>SharedPreference<\/code> \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c EncryptedSharedPreferences. PrefKeyEncryptionScheme \u0441\u0445\u0435\u043c\u0430 \u0448\u0438\u0444\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u043b\u044f \u043a\u043b\u044e\u0447\u0435\u0439 \u0432 <code>SharedPreferences<\/code>, \u0430 PrefValueEncryptionScheme \u0441\u0445\u0435\u043c\u0430 \u0448\u0438\u0444\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u043b\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0432 <code>SharedPreferences<\/code>.  <br \/>\u0418 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0441\u0430\u043c\u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u043f\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044e \u043f\u0438\u043d\u0430 \u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044e \u0435\u0433\u043e.<\/p>\n<p>\u042f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043b\u0438 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u043c \u043c\u0435\u0442\u043e\u0434 getPin()? \u0414\u0430. \u041f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0441 \u0443\u0436\u0435 \u0437\u0430\u0448\u0438\u0444\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c sharedprefs \u0438 \u0434\u0435\u0448\u0438\u0444\u0440\u0443\u0435\u0442\u0441\u044f \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430. \u041f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c, \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0441\u043b\u0438 \u0432\u044b \u043d\u0435 \u0440\u0435\u0448\u0438\u0442\u0435 \u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043b\u043e\u0433 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c \u043f\u0438\u043d\u043e\u043c.<\/p>\n<h2>\u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0430 UI<\/h2>\n<p>\u041e\u0442\u0447\u0430\u0441\u0442\u0438 \u0438\u043c\u0435\u043d\u043d\u043e \u0438\u0437-\u0437\u0430 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043d\u0438\u0433\u0434\u0435 \u0432 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0435 \u043d\u0435\u0442 \u0431\u043e\u043b\u0435\u0435 \u0443\u0434\u043e\u0431\u043d\u044b\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u0434\u043b\u044f PinLockScreen \u0441 JetpackCompose \u044f \u0440\u0435\u0448\u0438\u043b \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u0435\u043d\u044c\u043a\u0438\u0439 \u0433\u0430\u0439\u0434, \u0434\u043b\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0441\u0432\u043e\u0438\u0445 \u0437\u043d\u0430\u043d\u0438\u0439 \u0438, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043f\u043e\u043c\u043e\u0449\u0438 \u0434\u0440\u0443\u0433\u0438\u043c. \u041a \u0441\u043b\u043e\u0432\u0443, \u0435\u0441\u0442\u044c <a href=\"https:\/\/github.com\/raheemadamboev\/pin-lock-compose\" rel=\"noopener noreferrer nofollow\">\u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 <\/a>\u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u043e\u0440\u0430\u0445 \u0433\u0438\u0442\u0445\u0430\u0431\u0430, \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u044e\u0449\u0430\u044f UI \u043f\u0438\u043d\u043b\u043e\u043a\u0430 (\u0431\u0435\u0437 \u043a\u0430\u043a\u043e\u0439-\u043b\u0438\u0431\u043e \u043b\u043e\u0433\u0438\u043a\u0438 \u0437\u0430\u0449\u0438\u0442\u044b), \u043e\u0434\u043d\u0430\u043a\u043e, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u0434\u043b\u044f \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u0435\u043d\u0438\u044f \u043b\u0435\u0433\u043a\u0438\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u0440\u0430\u0439\u043d\u0435 \u043d\u0435\u0436\u0435\u043b\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c.<\/p>\n<p>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0446\u0432\u0435\u0442\u043e\u0432 \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u0446\u0432\u0435\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f \u043f\u0440\u043e\u043f\u0438\u0441\u0430\u043b \u0432 Theme, \u0441\u0434\u0435\u043b\u0430\u043d\u043e \u044d\u0442\u043e \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0442\u0435\u043c\u043d\u0443\u044e \u0438 \u0441\u0432\u0435\u0442\u043b\u0443\u044e \u0442\u0435\u043c\u0443, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043b\u044e\u0431\u044b\u0435 \u0446\u0432\u0435\u0442\u0430.<\/p>\n<p> \u0414\u0430\u043b\u0435\u0435 \u0446\u0432\u0435\u0442\u0430 \u0432 \u043c\u043e\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f \u0442\u0430\u043a:<\/p>\n<pre><code class=\"kotlin\">MaterialTheme.colorScheme.tertiary<\/code><\/pre>\n<p>\u0421\u0430\u043c\u043e\u0435 \u0433\u043b\u0430\u0432\u043d\u043e\u0435 \u0432 \u043f\u0438\u043d\u043b\u043e\u043a\u0435 \u044d\u0442\u043e \u043a\u043b\u0430\u0432\u0438\u0430\u0442\u0443\u0440\u0430, \u0430 \u043e\u043d\u0430 \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u043a\u043d\u043e\u043f\u043e\u043a, \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u043a\u043d\u043e\u043f\u043a\u0443, \u0432 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0431\u0443\u0434\u0435\u043c \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c content \u0441 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0435\u0439 Composable, \u0442\u043a \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430 \u0431\u0443\u0434\u0435\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 Text().<\/p>\n<pre><code>@Composable private fun KeyButton(     onClick: () -&gt; Unit,     shape: Shape = RoundedCornerShape(100),     content: @Composable () -&gt; Unit ) {     Box(         modifier = Modifier             .padding(8.dp)             .clip(shape)             .background(                 color = MaterialTheme.colorScheme.tertiary,                 shape = RoundedCornerShape(100)             )             .clickable(onClick = onClick)             .defaultMinSize(minWidth = 95.dp, minHeight = 95.dp)             .padding(4.dp),         contentAlignment = Alignment.Center     ) {         CompositionLocalProvider(LocalContentColor provides MaterialTheme.colorScheme.secondary) {             content()         }     } }<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0441\u0430\u043c\u0430 \u043a\u043b\u0430\u0432\u0438\u0430\u0442\u0443\u0440\u0430, \u044f \u043d\u0435 \u0434\u043e\u0434\u0443\u043c\u0430\u043b\u0441\u044f \u043d\u0438 \u0434\u043e \u0447\u0435\u0433\u043e \u043a\u0440\u043e\u043c\u0435 \u043a\u0430\u043a \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043a\u043b\u0430\u0432\u0438\u0430\u0442\u0443\u0440\u0443 \u0432 \u0432\u0438\u0434\u0435 \u0441\u043f\u0438\u0441\u043a\u0430 \u0438\u0437 \u0441\u043f\u0438\u0441\u043a\u043e\u0432 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0440\u044f\u0434\u0430 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432. \u0414\u0430\u043d\u043d\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0443\u0447\u0435\u0431\u043d\u044b\u043c, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u043d\u0435 \u0432\u044b\u043d\u043e\u0448\u0443 \u0441\u0442\u0440\u043e\u043a\u0438 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u044b. \u0415\u0441\u043b\u0438 \u0432\u044b \u0434\u0435\u043b\u0430\u0435\u0442\u0435 \u0441\u0432\u043e\u0439 \u043f\u0440\u043e\u0435\u043a\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0437\u0432\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0438\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 \u044d\u0442\u043e \u0432 \u043a\u043e\u043c\u043c\u0435\u0440\u0446\u0438\u0438, \u0442\u043e \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0432\u0441\u0435 \u044d\u0442\u043e \u043f\u0435\u0440\u0435\u043d\u0435\u0441\u0442\u0438 \u0432 \u0440\u0435\u0441\u0443\u0440\u0441\u044b, \u0430 \u0441\u0430\u043c \u0441\u043f\u0438\u0441\u043e\u043a \u043a\u043d\u043e\u043f\u043e\u043a \u0432\u044b\u043d\u0435\u0441\u0442\u0438 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0438\u043b\u0438 \u0436\u0435 \u043a\u043b\u0430\u0441\u0441.<\/p>\n<pre><code class=\"kotlin\">@Composable private fun Keyboard( ) {     val listKeys = listOf(         listOf(\"1\", \"2\", \"3\"),         listOf(\"4\", \"5\", \"6\"),         listOf(\"7\", \"8\", \"9\"),         listOf(\"del\", \"0\", \"OK\")     )      Column(         modifier = Modifier             .background(color = MaterialTheme.colorScheme.background)             .fillMaxSize()             .padding(bottom = 100.dp),         verticalArrangement = Arrangement.Bottom,         horizontalAlignment = Alignment.CenterHorizontally,     ) {         Spacer(modifier = Modifier.height(100.dp))          listKeys.forEach { rows -&gt;             Row {                 rows.forEach {                     KeyButton(                         onClick = {                                                     }                     ) {                         when (it) {                             \"del\" -&gt; {                                 Icon(                                     painter = painterResource(id = R.drawable.del_icon),                                     contentDescription = \"Clear\",                                     modifier = Modifier                                         .size(30.dp),                                     tint = MaterialTheme.colorScheme.secondary                                 )                             }                              \"OK\" -&gt; {                                 Icon(                                     imageVector = Icons.Default.Check,                                     contentDescription = \"Success\",                                     modifier = Modifier                                         .size(35.dp),                                     tint = MaterialTheme.colorScheme.secondary                                 )                             }                              else -&gt; Text(                                 text = it,                                 fontSize = 30.sp,                                 fontWeight = FontWeight.Medium,                                 color = MaterialTheme.colorScheme.secondary                             )                         }                     }                 }             }         }     } }<\/code><\/pre>\n<p>Column \u0432\u043d\u0443\u0442\u0440\u0438, \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043f\u0440\u043e\u0445\u043e\u0436\u0443\u0441\u044c \u043f\u043e \u0441\u043f\u0438\u0441\u043a\u0443, \u043e\u0431\u0440\u0430\u0437\u0443\u044f \u0442\u0435\u043c \u0441\u0430\u043c\u044b\u043c rows, \u043e\u043d\u0438 \u0438 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0440\u044f\u0434\u0430\u043c\u0438 \u0441 \u043a\u043d\u043e\u043f\u043a\u0430\u043c\u0438. \u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0432 \u0441\u0442\u043e\u043b\u0431\u0446\u0435 \u0441\u043f\u0435\u0446\u0441\u0438\u043c\u0432\u043e\u043b \u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0441\u044c \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435\u043c when, \u0432 \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u043d\u0435 \u043a\u043d\u043e\u043f\u043a\u0430 \u041e\u041a \u0438\u043b\u0438 \u0443\u0434\u0430\u043b\u0438\u0442\u044c, \u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u043f\u0438\u0441\u044b\u0432\u0430\u044e \u0432 \u043a\u043e\u043d\u0442\u0435\u043d\u0442 \u043a\u043d\u043e\u043f\u043a\u0438 \u0442\u0435\u043a\u0441\u0442.<br \/>\u0414\u0430\u043b\u0435\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0432\u043e\u0442 \u0442\u0430\u043a\u0438\u0435 \u0442\u043e\u0447\u043a\u0438 \u0434\u043b\u044f \u0432\u0432\u043e\u0434\u0430 \u0438 \u0442\u0435\u043a\u0441\u0442<\/p>\n<figure class=\"\"><\/figure>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0434\u0432\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 &#8212; \u0442\u0435\u043a\u0441\u0442 \u0438 \u0441\u0430\u043c\u0438 \u0442\u043e\u0447\u043a\u0438<\/p>\n<pre><code class=\"kotlin\">@Composable private fun PinDot(isFilled: Boolean) {     Box(         modifier = Modifier             .padding(10.dp)             .size(30.dp)             .background(                 if (isFilled) MaterialTheme.colorScheme.tertiary else                     if (isSystemInDarkTheme()) White                     else Color.Gray, CircleShape             )     ) }<\/code><\/pre>\n<p>\u0412 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u044e isFilled \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0442\u043e\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c, \u043a\u0430\u043a \u0444\u043b\u0430\u0433 \u0434\u043b\u044f \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043f\u0440\u0438 \u0432\u0432\u043e\u0434\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u0430.<\/p>\n<h2>ViewModel<\/h2>\n<p>\u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c \u0442\u0435\u043a\u0441\u0442 \u0432\u0432\u043e\u0434\u0430 \u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442\u044c \u043f\u043e\u00a0\u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u0438 \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0432\u044c\u044e\u043c\u043e\u0434\u0435\u043b\u044c\u043a\u0443, \u0432\u00a0\u043d\u0435\u0439 \u0431\u0443\u0434\u0435\u0442 \u043e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u043b\u043e\u0433\u0438\u043a\u0430 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439, \u0432\u00a0\u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u043f\u0430\u0440\u043e\u043b\u044f \u0432\u00a0KeyStore.<br \/>\u0414\u043b\u044f\u00a0\u0441\u0430\u043c\u043e\u0439 ViewModel \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u043c\u043e\u0434\u0435\u043b\u044c state. \u0418 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0441\u00a0events, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u044b \u043a\u0430\u043a\u00a0\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0432\u00a0\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438.<\/p>\n<pre><code class=\"kotlin\">data class PinLockState(     val isAuthenticated: Boolean = false,     val inputPin: String = \"\",     val error: ErrorPin? = null,     val confirmPin: String? = null )  sealed interface PinLockEvent {      data class AddDigit(val digit: String) : PinLockEvent     data object DeleteDigit : PinLockEvent     data object ClearPin : PinLockEvent     data object CheckPin : PinLockEvent  }<\/code><\/pre>\n<p>\u0412 \u0441\u0442\u0435\u0439\u0442\u0435 \u043b\u0435\u0436\u0438\u0442 \u0444\u043b\u0430\u0436\u043e\u043a isAuthenticated \u0434\u043b\u044f\u00a0\u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c, \u0435\u0441\u0442\u044c\u00a0\u043b\u0438 \u0443\u00a0\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0443\u0436\u0435 \u043f\u0438\u043d\u043a\u043e\u0434 \u0438\u043b\u0438\u00a0\u043d\u0435\u0442, inputPin\u00a0\u2014 \u0441\u0430\u043c \u043f\u0438\u043d\u043a\u043e\u0434, \u043a\u0443\u0434\u0430 \u0431\u0443\u0434\u0443\u0442 \u0432\u0445\u043e\u0434\u0438\u0442\u044c \u0432\u0432\u043e\u0434\u0438\u043c\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, error\u00a0\u2014 \u043e\u0448\u0438\u0431\u043a\u0438, \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u0442\u0430\u043a\u0436\u0435 \u0432\u00a0\u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0444\u043b\u0430\u0433\u0430, \u0434\u043b\u044f\u00a0\u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0432\u0445\u043e\u0434\u0430, confirmPin\u00a0\u2014 \u0442\u043e\u0436\u0435 \u043f\u0438\u043d\u043a\u043e\u0434, \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0443\u0436\u0435\u043d \u0434\u043b\u044f\u00a0\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u0438 \u0442\u043e\u043b\u044c\u043a\u043e.<\/p>\n<p>\u0421\u0430\u043c\u0430 ViewModel \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0430 \u043d\u0438\u0436\u0435.<\/p>\n<pre><code class=\"kotlin\">class PinLockViewModel(     private val keystoreManager: KeystoreManager ) : ViewModel() {      private val _state = MutableStateFlow(PinLockState())     val state: StateFlow&lt;PinLockState&gt; = _state      init {         val pinSet = keystoreManager.getPin().isNullOrBlank()         _state.update {             it.copy(                 isAuthenticated = !pinSet             )         }     }      fun onEvent(event: PinLockEvent) {         when (event) {             is PinLockEvent.DeleteDigit -&gt; {                 _state.update {                     it.copy(                         inputPin = it.inputPin.substring(0, it.inputPin.length - 1)                     )                 }             }             is PinLockEvent.AddDigit -&gt; {                 _state.update {                     it.copy(                         inputPin = it.inputPin.plus(event.digit)                     )                 }             }             is PinLockEvent.ClearPin -&gt; {                 _state.update {              <\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-427577","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/427577","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=427577"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/427577\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=427577"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=427577"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=427577"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}