Android 指纹解锁和MD5加密密码
2017-04-17 14:35
441 查看
代码下载在文末。
验证keyguardManager.isKeyguardSecure()是否开启:
判断是否录入指纹:
调起指纹验证Dialog:
Android MD5加密
指纹解锁
验证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值 * * @param string * @return */ public static String getStringMD5(String string) { if (TextUtils.isEmpty(string)) { return ""; } MessageDigest md5 = null; try { md5 = MessageDigest.getInstance("MD5"); byte[] bytes = md5.digest(string.getBytes()); String result = ""; for (byte b : bytes) { String temp = Integer.toHexString(b & 0xff); if (temp.length() == 1) { temp = "0" + temp; } result += temp; } return result; } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return ""; }
/** * 对字符串多次MD5加密 * * @param string * @param times * @return */ public static String getStringMD5MultiTimes(String string, int times) { if (TextUtils.isEmpty(string)) { return ""; } String md5 = getStringMD5(string); for (int i = 0; i < times - 1; i++) { md5 = getStringMD5(md5); } return getStringMD5(md5); }
/** * MD5加盐 * * @param string * @param salt * @return */ public static String getMD5ByStringAndSalt(String string, String salt) { if (TextUtils.isEmpty(string)) { return ""; } MessageDigest md5 = null; try { md5 = MessageDigest.getInstance("MD5"); byte[] bytes = md5.digest((string + salt).getBytes()); String result = ""; for (byte b : bytes) { String temp = Integer.toHexString(b & 0xff); if (temp.length() == 1) { temp = "0" + temp; } result += temp; } return result; } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return ""; }
代码下载 (免积分)
Android 指纹识别Android MD5加密
相关文章推荐
- Android 使用MD5对SharedPreferences密码进行加密
- Android中使用MD5对密码进行加密
- 用 MD5 加密数据库中的用户密码
- asp.net 2.0中md5密码加密
- 用彩虹表破解MD5、LM Hash等复杂加密密码
- 如何保护好经过MD5加密过的密码
- java中字符串 MD5密码的加密与验证
- 为大家经常为md5加密过的常用admin,admin888,0000密码
- 用MD5处理明文密码加密
- .net自动发送邮件,适用于MD5或sha1加密后的密码取
- asp.net中密码加密MD5
- 用Gpu破解md5、sha1等加密密码的软件
- 使用C# 用MD5进行密码加密源代码
- Android 用MD5加密算法加密密码
- (转)Oracle、SQL Server下MD5+Base64密码加密实现
- 使用MD5对密码进行加密
- 用 MD5 加密数据库中的用户密码
- 用 MD5 加密数据库中的用户密码
- 对密码字段进行加密(MD5)
- MD5 密码加密