÷è÷ë²Ù×÷ϵͳÖеÄÇå¾²¹¦Ð§ÔõÑù±£»¤ÄãµÄСÎÒ˽¼ÒÐÅÏ¢£¿
÷è÷ë²Ù×÷ϵͳÖеÄÇå¾²¹¦Ð§ÔõÑù±£»¤ÄãµÄСÎÒ˽¼ÒÐÅÏ¢£¿
Ëæ×Å»¥ÁªÍøµÄ¿ìËÙÉú³¤£¬Ð¡ÎÒ˽¼ÒÐÅÏ¢µÄÇå¾²³ÉΪÁËÒ»¸öÓú·¢Ö÷ÒªµÄÎÊÌâ¡£ÈËÃÇÔ½À´Ô½¹ØעСÎÒ˽¼ÒÐÅÏ¢µÄ±£»¤£¬ÓÈÆäÊÇÔÚʹÓòÙ×÷ϵͳµÄʱ¼ä¡£×÷ΪÖйú×ÔÖ÷Ñз¢µÄ°²×¿Ì滻Ʒ£¬÷è÷ë²Ù×÷ϵͳÒÔÆä׿ԽµÄÇå¾²ÐÔÄܶø±¸ÊܹØ×¢¡£±¾ÎĽ«ÏÈÈÝ÷è÷ë²Ù×÷ϵͳÖеÄÇå¾²¹¦Ð§£¬²¢Ê÷Ä£ÔõÑùʹÓÃÕâЩ¹¦Ð§±£»¤ÄãµÄСÎÒ˽¼ÒÐÅÏ¢¡£
Óû§Éí·ÝÑéÖ¤
ÔÚ÷è÷ë²Ù×÷ϵͳÖУ¬Óû§ÐèÒª¾ÙÐÐÉí·ÝÑéÖ¤²Å»ª»á¼ûСÎÒ˽¼ÒÐÅÏ¢¡£Í¨¹ýÉèÖÃÃÜÂë¡¢PINÂ롢ģʽËøµÈ·½·¨£¬Óû§¿ÉÒÔÓÐÓñ£»¤×Ô¼ºµÄÊÖ»ú¡£ÒÔÏÂÊÇÒ»¸ö»ùÓÚ÷è÷ëϵͳµÄÓû§Éí·ÝÑéÖ¤µÄʾÀý´úÂ룺
// ½¨ÉèÃÜÂëËøÆÁ KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE); KeyguardManager.KeyguardLock lock = keyguardManager.newKeyguardLock(Context.KEYGUARD_SERVICE); lock.disableKeyguard(); // ÑéÖ¤ÃÜÂë private boolean verifyPassword(String userInputPassword) { String correctPassword = "examplePassword"; // ׼ȷµÄÃÜÂë return correctPassword.equals(userInputPassword); }
µÇ¼ºó¸´ÖÆ
ÉÏÊö´úÂëÖУ¬Óû§ÐèÒªÊäÈëÃÜÂë¾ÙÐÐÉí·ÝÑéÖ¤¡£Í¨¹ý verifyPassword ÒªÁ죬ϵͳ½«¼ì²éÓû§ÊäÈëµÄÃÜÂëÊÇ·ñÓëÔ¤ÉèÃÜÂëÒ»Ö¡£ËäÈ»£¬ÎªÁË°ü¹ÜÇå¾²ÐÔ£¬ÏÖʵӦÓÃÖÐͨ³£»áʹÓøüÖØ´óµÄ¼ÓÃÜËã·¨¡£
Ó¦ÓÃȨÏÞÖÎÀí
÷è÷ë²Ù×÷ϵͳÖеÄÓ¦ÓÃȨÏÞÖÎÀí¹¦Ð§¿ÉÒÔ×ÊÖúÓû§ÑÏ¿á¿ØÖÆÿ¸öÓ¦ÓöÔСÎÒ˽¼ÒÐÅÏ¢µÄ»á¼ûȨÏÞ¡£ÒÔÏÂÊÇÒ»¸ö»ùÓÚ÷è÷ëϵͳµÄÓ¦ÓÃȨÏÞÖÎÀíµÄʾÀý´úÂ룺
// ¼ì²éÓ¦ÓÃȨÏÞ private boolean checkPermission(String permission) { int permissionResult = checkSelfPermission(permission); return permissionResult == PackageManager.PERMISSION_GRANTED; } // ÇëÇóÓ¦ÓÃȨÏÞ private void requestPermission(String[] permissions) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { requestPermissions(permissions, PERMISSION_REQUEST_CODE); } }
µÇ¼ºó¸´ÖÆ
ÉÏÊö´úÂëÖУ¬Í¨¹ý checkPermission ÒªÁ죬Óû§¿ÉÒÔ¼ì²éÓ¦ÓÃÊÇ·ñ¾ßÓÐijÏîȨÏÞ¡£ÈôÊÇûÓÐȨÏÞ£¬Óû§¿ÉÒÔͨ¹ý requestPermission ÒªÁìÇëÇóÏìÓ¦µÄȨÏÞ¡£ÕâÑù£¬Óû§¾ÍÄܸüºÃµØÕÆ¿ØÓ¦ÓöÔСÎÒ˽¼ÒÐÅÏ¢µÄ»á¼ûȨÏÞ¡£
Êý¾Ý¼ÓÃÜ
÷è÷ë²Ù×÷ϵͳÌṩÁËÒ»Ì׸ßЧ¿É¿¿µÄ¼ÓÃÜËã·¨£¬¿ÉÒÔ¶ÔСÎÒ˽¼ÒÐÅÏ¢¾ÙÐмÓÃÜ´¦Öóͷ££¬´Ó¶ø±£»¤Óû§µÄÒþ˽²»±»¶ñÒâ»á¼û¡£ÒÔÏÂÊÇÒ»¸ö»ùÓÚ÷è÷ëϵͳµÄÊý¾Ý¼ÓÃܵÄʾÀý´úÂ룺
// ×Ö·û´®¼ÓÃÜ private String encryptString(String input) { try { KeyGenerator keyGenerator = KeyGenerator.getInstance("AES"); keyGenerator.init(256); SecretKey secretKey = keyGenerator.generateKey(); Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.ENCRYPT_MODE, secretKey); byte[] encryptedBytes = cipher.doFinal(input.getBytes()); return Base64.encodeToString(encryptedBytes, Base64.DEFAULT); } catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | IllegalBlockSizeException | BadPaddingException e) { e.printStackTrace(); } return null; }
µÇ¼ºó¸´ÖÆ
ÉÏÊö´úÂëÖУ¬Í¨¹ý encryptString ÒªÁ죬Óû§¿ÉÒÔ½«×Ö·û´®¾ÙÐÐAES¼ÓÃÜ¡£¼ÓÃܺóµÄ×Ö·û´®½«¸üÄѱ»Æƽ⣬´Ó¶øÌá¸ßÁËСÎÒ˽¼ÒÐÅÏ¢µÄÇå¾²ÐÔ¡£
×ܽ᣺
÷è÷ë²Ù×÷ϵͳǿʢµÄÇå¾²¹¦Ð§¶Ô±£»¤Ð¡ÎÒ˽¼ÒÐÅÏ¢Æðµ½ÁËÖ÷Òª×÷Óá£Ëüͨ¹ýÓû§Éí·ÝÑéÖ¤¡¢Ó¦ÓÃȨÏÞÖÎÀíºÍÊý¾Ý¼ÓÃܵȹ¦Ð§£¬ÓÐÓñ£»¤ÁËÓû§µÄÒþ˽ÐÅÏ¢¡£ËäÈ»£¬ÔÚÏÖʵӦÓÃÖУ¬ÎÒÃÇ»¹ÐèҪƾ֤ÏêϸÐèÇóºÍÇé¾³£¬×ÛºÏʹÓÃÕâЩÇå¾²¹¦Ð§£¬ÒÔÈ·±£Ð¡ÎÒ˽¼ÒÐÅÏ¢µÄ×î´óÇå¾²¡£Òò´Ë£¬ÎÒÃÇÇ¿ÁÒÍƼö÷è÷ë²Ù×÷ϵͳ×÷ΪһÖÖ¿É¿¿µÄÇ徲ѡÔñ¡£
ÒÔÉϾÍÊÇ÷è÷ë²Ù×÷ϵͳÖеÄÇå¾²¹¦Ð§ÔõÑù±£»¤ÄãµÄСÎÒ˽¼ÒÐÅÏ¢£¿µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡