2.3. Mobil ilovani ishlashi bo'yicha yo'riqnoma
Mobil ilovani ishga tushirish uchun Android Studio dasturining emulatoridan foydalanishimiz mumkin va bundan tashqari mobil telefon bilan kompyuterni bog’lab beruvchi dasturlarimiz ham bor. Bulardan biri LetsView ilovasi , bu ilova orqali ishimiz ancha oson bo’ladi. Avvalo, Letsview ni ishga tushuramiz va unda ilovani ko’rib chiqamiz. (2.17-rasm)
2.17-rasm. Emulatorda mobil ilovaning ikonka tarzda ko’rinishi
Endi esa ilovaga kiramiz. Ilovaga kirganimizda quyidagi ko’rinishni ko’rishimiz mumkin:
2.18-rasm. Mobil ilovaga kirishdagi animatsiyali ko’rinish
2.19-rasm. Mobil ilovaga kirgandagi ko’rinish
2.19-rasm da ilovamizni biometrik ma’lumotlar orqali tekshirib o’tamiz va undan keyin tekshirish muvaffaqiyatli bo’lsa quyidagi oyna hosil bo’ladi:
2.20-rasm. Biomertiya orqali yashirilgan maxfiy xabarlar ro’yxati
Bu rasmda maxfiy xabarlar ro’yxati turadi, ya’ni hosil qilgan maxfiy xabarlar jamlanmasi turadi va shu oynani o’zida maxfiy xabarni yaratish uchun pastda turgan tugma ham bor. Biz tugmani bosamiz, keyin xabarni kiritamiz va xabarimizni shifrlaymiz.
2.21-rasm. Xabarni kiritish oynasi
Shundan so’ng biz xabarimizni kiritamiz
2.22-rasm. Xabarni kiritish va xabarni shifrlash jarayoni
Xabarni kiritgandan keyin esa pastdagi tugmani bosamiz va bizga biometriya orqali shifrlash dialogi hosil bo’ladi va biz biometriyamiz orqali maxfiy xabar hosil qilamiz.
2.23-rasm. Secret message saqlangandagi ko’rinish
Shundan so’ng bu oynadan chiqamiz (2.23-rasm), maxfiy xabarlar ro’yxatimizni o’zgarganligini ko’rishimiz mumkin bo’ladi.
2.24-rasm. Biomertiya orqali yashirilgan maxfiy xabarlar ro’yxati o’zgargandagi ko’rinishi
Endi esa biz biometrik ma’lumotlar orqali maxfiy xabarlarimizni deshifrlaymiz ya’ni shifrlashga teskari jarayonni amalga oshiramiz. Buning uchun biz ro’yxatdagi istalgan maxfiy xabarni ustiga bosamiz va quyidagicha oyna hosil bo’ladi:
2.25-rasm. Maxfiy xabarni deshifrlash oynasi
Oxirida esa maxfiy xabarimizni deshifrlash uchun albatta biometrik tasvirlarga murojaat qilamiz va natijamiz quyidagicha bo’ladi:
2.26-rasm. Maxfiy xabarimiz biometrik ma’lumotlar orqali deshifrlangandan keyingi ko’rinishi
Qisman ilovamizning mohiyati va ko’rinishi shundan iborat, avval takidlaganimizdik, ilovaning har bir jarayoni biometrik ma’lumotlar bilan uzviy bog’liq holda ishlab chiqilgan.
Keling siz bilan ma’lumotlarni shifirlash jarayonidagi 2.22 – rasmning dasturiy kodi to’g’risida gaplashaylik
Kod qismi:
import android.content.DialogInterface
import android.os.Build
import android.os.Bundle
import android.text.TextUtils
import android.view.View
import androidx.annotation.RequiresApi
import androidx.appcompat.app.AppCompatActivity
import androidx.biometric.BiometricPrompt
import kotlinx.android.synthetic.main.activity_encryption.*
import javax.crypto.Cipher
class EncryptionActivity : AppCompatActivity(),
BiometricAuthListener {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_encryption)
}
@RequiresApi(Build.VERSION_CODES.M)
fun onClickEncryptMessage(view: View) {
val message = textInputMessage.editText?.text.toString().trim()
if (!TextUtils.isEmpty(message)) {
if (BiometricUtil.isBiometricReady(this)) {
showBiometricPromptToEncrypt()
} else {
showAlertToSetupBiometric()
}
}
}
private fun confirmInput() {
textInputMessage.editText?.text = null
CommonUtils.displayToast(this, getString(R.string.message_saved))
}
private fun showAlertToSetupBiometric() {
CommonUtils.displayMessage(
this,
getString(R.string.message_encryption_failed),
getString(R.string.message_no_biometric),
) { dialog: DialogInterface, index: Int ->
BiometricUtil.lunchBiometricSettings(this)
}
}
@RequiresApi(Build.VERSION_CODES.M)
private fun showBiometricPromptToEncrypt() {
// Create Cryptography Object
val cryptoObject = BiometricPrompt.CryptoObject(
CryptographyUtil.getInitializedCipherForEncryption()
)
// Show BiometricPrompt
BiometricUtil.showBiometricPrompt(
activity = this,
listener = this,
cryptoObject = cryptoObject
)
}
override fun onBiometricAuthenticationSuccess(result: BiometricPrompt.AuthenticationResult) {
result.cryptoObject?.cipher?.let {
val message = textInputMessage.editText?.text.toString().trim()
if (!TextUtils.isEmpty(message)) {
encryptAndSave(message, it)
confirmInput()
}
}
}
override fun onBiometricAuthenticationError(errorCode: Int, errorMessage: String) {
CommonUtils.displayToast(this, "Biometric error: $errorMessage")
}
private fun encryptAndSave(plainTextMessage: String, cipher: Cipher) {
val encryptedMessage = CryptographyUtil.encryptData(plainTextMessage, cipher)
// Save Encrypted Message
PreferenceUtil.storeEncryptedMessage(
applicationContext,
prefKey = encryptedMessage.savedAt.toString(),
encryptedMessage = encryptedMessage
)
Bu biz ko’rib turgan 2.22-rasmning dasturiy kod qismi hisoblanadi. Bu yerda aytganimizdek ma’lumotlarni maxfiy qilish jarayoni aks ettirilgan.
Shu tarzda har bir jarayon ishlab chiqilgan.
Do'stlaringiz bilan baham: |