Android 指纹解锁和MD5加密密码

本文介绍了如何在Android应用中使用KeyguardManager检查锁屏保护,FingerprintManager验证用户指纹,以及MD5加密技术的应用。作者还讨论了在指纹未注册或锁屏功能禁用时的处理流程和加密对话框的实现过程。
摘要由CSDN通过智能技术生成

验证keyguardManager.isKeyguardSecure()是否开启:

KeyguardManager keyguardManager = getSystemService(KeyguardManager.class);

if (!keyguardManager.isKeyguardSecure()) {

// Show a message that the user hasn’t set up a fingerprint or lock screen.

Toast.makeText(this, getResources().getString(R.string.not_set_secure_lock),

Toast.LENGTH_LONG).show();

purchaseButton.setEnabled(false);

purchaseButtonNotInvalidated.setEnabled(false);

return;

}

判断是否录入指纹:

FingerprintManager fingerprintManager = getSystemService(FingerprintManager.class);

if (!fingerprintManager.hasEnrolledFingerprints()) {

purchaseButton.setEnabled(false);

// This happens when no fingerprints are registered.

Toast.makeText(this, getResources().getString(R.string.no_fingerprint_register),

Toast.LENGTH_LONG).show();

return;

}

调起指纹验证Dialog:

private class PurchaseButtonClickListener implements View.OnClickListener {

Cipher cipher;

String mKeyName;

PurchaseButtonClickListener(Cipher cipher, String keyName) {

this.cipher = cipher;

mKeyName = keyName;

}

@Override

public void onClick(View view) {

findViewById(R.id.confirmation_message).setVisibility(View.GONE);

findViewById(R.id.encrypted_message).setVisibility(View.GONE);

// Set up the crypto object for later. The object will be authenticated by use

// of the fingerprint.

if (initCipher(cipher, mKeyName)) {

// Show the fingerprint dialog. The user has the option to use the fingerprint with

// crypto, or you can fall back to using a server-side verified password.

FingerprintAuthenticationDialogFragment fragment

= new FingerprintAuthenticationDialogFragment();

fragment.setCryptoObject(new FingerprintManager.CryptoObject(cipher));

boolean useFingerprintPreference = sharedPreferences

.getBoolean(getString(R.string.use_fingerprint_to_authenticate_key),

true);

if (useFingerprintPreference) {

fragment.setStage(FingerprintAuthenticationDialogFragment.Stage.FINGERPRINT);

} else {

fragment.setStage(FingerprintAuthenticationDialogFragment.Stage.PASSWORD);

}

fragment.show(getFragmentManager(), DIALOG_FRAGMENT_TAG);

} else {

// This happens if the lock screen has been disabled or or a fingerprint got

// enrolled. Thus show the dialog to authenticate with their password first

// and ask the user if they want to authenticate with fingerprints in the

// future

FingerprintAuthenticationDialogFragment fragment

= new FingerprintAuthenticationDialogFragment();

fragment.setCryptoObject(new FingerprintManager.CryptoObject(cipher));

fragment.setStage(

FingerprintAuthenticationDialogFragment.Stage.NEW_FINGERPRINT_ENROLLED);

fragment.show(getFragmentManager(), DIALOG_FRAGMENT_TAG);

}

}

}

MD5加密


这里写图片描述

/**

  • 计算文件的 MD5 值

  • @param file

  • @return

*/

public static String getFileMD5(File file) {

if (file == null || !file.isFile() || !file.exists()) {

return “”;

}

FileInputStream in = null;

String result = “”;

byte buffer[] = new byte[8192];

int len;

try {

MessageDigest md5 = MessageDigest.getInstance(“MD5”);

in = new FileInputStream(file);

while ((len = in.read(buffer)) != -1) {

md5.update(buffer, 0, len);

}

byte[] bytes = md5.digest();

for (byte b : bytes) {

String temp = Integer.toHexString(b & 0xff);

if (temp.length() == 1) {

temp = “0” + temp;

}

result += temp;

}

} catch (Exception e) {

e.printStackTrace();

} finally {

if (null != in) {

try {

in.close();

} catch (IOException e) {

e.printStackTrace();

}

}

}

return result;

}

/**

  • 计算字符串MD5值
    自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数初中级Android工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则近万的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年Android移动开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。

img

img

img

img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点,真正体系化!

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!

如果你觉得这些内容对你有帮助,可以扫码获取!!(资料价值较高,非无偿)

《960全网最全Android开发笔记》

《379页Android开发面试宝典》

《507页Android开发相关源码解析》

因为文件太多,全部展示会影响篇幅,暂时就先列举这些部分截图

《Android学习笔记总结+移动架构视频+大厂面试真题+项目实战源码》,点击传送门即可获取!

mg-SE5eLp3S-1711550771397)]

《379页Android开发面试宝典》

[外链图片转存中…(img-Qkig9iT1-1711550771397)]

《507页Android开发相关源码解析》

[外链图片转存中…(img-NOV8w0Wf-1711550771398)]

因为文件太多,全部展示会影响篇幅,暂时就先列举这些部分截图

《Android学习笔记总结+移动架构视频+大厂面试真题+项目实战源码》,点击传送门即可获取!
  • 15
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值