÷è÷ë²Ù×÷ϵͳÖеÄÒþ˽±£»¤¹¦Ð§ÔõÑùÈ·±£ÄãµÄÊý¾ÝÇå¾²£¿
÷è÷ë²Ù×÷ϵͳÖеÄÒþ˽±£»¤¹¦Ð§ÔõÑùÈ·±£ÄãµÄÊý¾ÝÇå¾²£¿
Ëæ×ÅÐÅÏ¢ÊÖÒÕµÄÒ»Ö±Éú³¤ºÍÆÕ¼°£¬ÈËÃÇÒ»Ñùƽ³£ÉúÑÄÖÐÌìÉúºÍ´¦Öóͷ£µÄÊý¾ÝÒ²Ô½À´Ô½¶à¡£È»¶ø£¬Óë´Ëͬʱ£¬Òþ˽й¶ºÍСÎÒ˽¼ÒÊý¾Ý±»ÀÄÓõÄΣº¦Ò²ÈÕÒæÑÏÖØ¡£ÎªÁ˱£»¤Óû§µÄÒþ˽£¬÷è÷ë²Ù×÷ϵͳÄÚÖÃÁËһϵÁÐÇ¿Ê¢µÄÒþ˽±£»¤¹¦Ð§£¬ÏÂÃ潫ÏêϸÏÈÈÝ÷è÷ë²Ù×÷ϵͳÖеÄÒþ˽±£»¤¹¦Ð§£¬²¢Ìṩ´úÂëʾÀý¡£
ȨÏÞ¿ØÖÆ
÷è÷ë²Ù×÷ϵͳͨ¹ýȨÏÞ¿ØÖƱ£»¤Óû§µÄÒþ˽Êý¾Ý¡£Óû§¿ÉÒÔÉèÖûá¼ûºÍʹÓÃËûÃǵÄÊý¾ÝµÄȨÏÞ£¬°üÀ¨Îļþ¡¢Ïà»ú¡¢Âó¿Ë·çµÈ¡£Ö»ÓлñµÃȨÏÞµÄÓ¦ÓóÌÐò²Å»ªÊ¹ÓÃÏà¹ØµÄ×°±¸»ò»á¼ûÌض¨µÄÎļþ¡£ÒÔÏÂÊÇÉèÖÃÏà»úȨÏ޵ĴúÂëʾÀý£º
// ÇëÇóÏà»úȨÏÞ if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA}, REQUEST_CAMERA_PERMISSION); } // ´¦Öóͷ£È¨ÏÞÇëÇóЧ¹û @Override public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { if (requestCode == REQUEST_CAMERA_PERMISSION) { if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { // Ïà»úȨÏÞÒÑÊÚȨ£¬¾ÙÐÐÏà»ú²Ù×÷ openCamera(); } else { // Ïà»úȨÏÞ±»¾Ü¾ø£¬ÎÞ·¨¾ÙÐÐÏà»ú²Ù×÷ showToast("Ïà»úȨÏÞ±»¾Ü¾ø"); } } }
µÇ¼ºó¸´ÖÆ
Êý¾Ý¼ÓÃÜ
÷è÷ë²Ù×÷ϵͳ֧³Ö¶ÔÊý¾Ý¾ÙÐмÓÃÜ£¬°üÀ¨´æ´¢ÔÚÉè±¹ØÁ¬ÄÊý¾ÝºÍ´«ÊäÀú³ÌÖеÄÊý¾Ý¡£Í¨¹ýʹÓüÓÃÜËã·¨£¬Óû§µÄÊý¾ÝÔÚ´æ´¢ºÍ´«ÊäÀú³ÌÖлñµÃÁ˱£»¤£¬ÎÞ·¨±»Î´ÊÚȨµÄÈË»á¼û»òÇÔÈ¡¡£ÒÔÏÂÊǶÔÎļþ¾ÙÐмÓÃÜÏ¢ÕùÃܵĴúÂëʾÀý£º
// Îļþ¼ÓÃÜ public void encryptFile(File file, String password) { try { // ʹÓÃAESËã·¨¾ÙÐÐÎļþ¼ÓÃÜ Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.ENCRYPT_MODE, generateKey(password)); InputStream inputStream = new FileInputStream(file); OutputStream outputStream = new FileOutputStream(file + ".encrypted"); byte[] buffer = new byte[1024]; int bytesRead; while ((bytesRead = inputStream.read(buffer)) != -1) { outputStream.write(cipher.update(buffer, 0, bytesRead)); } outputStream.write(cipher.doFinal()); inputStream.close(); outputStream.close(); } catch (Exception e) { e.printStackTrace(); } } // Îļþ½âÃÜ public void decryptFile(File file, String password) { try { // ʹÓÃAESËã·¨¾ÙÐÐÎļþ½âÃÜ Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.DECRYPT_MODE, generateKey(password)); InputStream inputStream = new FileInputStream(file); OutputStream outputStream = new FileOutputStream(file.getParent() + "/" + file.getName().replace(".encrypted", "")); byte[] buffer = new byte[1024]; int bytesRead; while ((bytesRead = inputStream.read(buffer)) != -1) { outputStream.write(cipher.update(buffer, 0, bytesRead)); } outputStream.write(cipher.doFinal()); inputStream.close(); outputStream.close(); } catch (Exception e) { e.printStackTrace(); } } // ÌìÉúAESÃÜÔ¿ private SecretKeySpec generateKey(String password) throws Exception { byte[] passwordBytes = password.getBytes("UTF-8"); MessageDigest digest = MessageDigest.getInstance("SHA-256"); byte[] key = digest.digest(passwordBytes); return new SecretKeySpec(key, "AES"); }
µÇ¼ºó¸´ÖÆ
ÄäÃû»¯´¦Öóͷ£
ÔÚijЩ³¡¾°Ï£¬Óû§¿ÉÄÜÐèÒª·ÖÏíÊý¾Ý£¬µ«²»Ïë͸¶×Ô¼ºµÄÕæʵÉí·ÝºÍÃô¸ÐÐÅÏ¢¡£÷è÷ë²Ù×÷ϵͳÌṩÁËÄäÃû»¯´¦Öóͷ£¹¦Ð§£¬¿ÉÒÔ¶ÔÓû§µÄÊý¾Ý¾ÙÐÐÍÑÃô»òÌæ»»£¬±£»¤Óû§µÄÒþ˽¡£ÒÔÏÂÊǵÐÊÖ»úºÅ¾ÙÐÐÍÑÃôµÄ´úÂëʾÀý£º
// ÊÖ»úºÅÍÑÃô public String desensitizePhoneNumber(String phoneNumber) { return phoneNumber.replaceAll("(\d{3})\d{4}(\d{4})", "$1****$2"); }
µÇ¼ºó¸´ÖÆ
ÒÔÉÏÊÇ÷è÷ë²Ù×÷ϵͳÖеIJ¿·ÖÒþ˽±£»¤¹¦Ð§ºÍ´úÂëʾÀý£¬Í¨¹ýºÏÀíÉèÖÃȨÏÞ¡¢Ê¹ÓÃÊý¾Ý¼ÓÃܺÍÄäÃû»¯´¦Öóͷ£µÈÊֶΣ¬÷è÷ë²Ù×÷ϵͳȷ±£Óû§µÄÊý¾ÝÇå¾²ºÍÒþ˽±£»¤¡£ÔÚʹÓòÙ×÷ϵͳʱ£¬Óû§Ò²Ó¦³ä·ÖÏàʶºÍʹÓÃÕâЩ¹¦Ð§£¬×èÖ¹Òþ˽й¶ºÍСÎÒ˽¼ÒÊý¾Ý±»ÀÄÓõÄΣº¦¡£
ÒÔÉϾÍÊÇ÷è÷ë²Ù×÷ϵͳÖеÄÒþ˽±£»¤¹¦Ð§ÔõÑùÈ·±£ÄãµÄÊý¾ÝÇå¾²£¿µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡