MD5验证安装包。一个apk位置,md5验证码
作者:互联网
public static boolean verifyInstallPackage(String packagePath, String crc) { try { MessageDigest sig = MessageDigest.getInstance("MD5"); File packageFile = new File(packagePath); InputStream signedData = new FileInputStream(packageFile); byte[] buffer = new byte[4096];//每次检验的文件区大小 long toRead = packageFile.length(); long soFar = 0; boolean interrupted = false; while (soFar < toRead) { interrupted = Thread.interrupted(); if (interrupted) break; int read = signedData.read(buffer); soFar += read; sig.update(buffer, 0, read); } byte[] digest = sig.digest(); String digestStr = bytesToHexString(digest);//将得到的MD5值进行移位转换 digestStr = digestStr.toLowerCase(); crc = crc.toLowerCase(); if (digestStr.equals(crc)) {//比较两个文件的MD5值,如果一样则返回true return true; } } catch (Exception e) { // TODO: handle exception return false; } return false; }it_remember 发布了40 篇原创文章 · 获赞 16 · 访问量 1万+ 私信 关注
标签:false,crc,read,interrupted,apk,digestStr,md5,安装包,MD5 来源: https://blog.csdn.net/qq_34812958/article/details/104187179