public static String computeMd5(@NonNull PackageInfo packageInfo) { String sourceDir = packageInfo.applicationInfo.sourceDir; File apkFile = new File(sourceDir); return computeMd5(apkFile); }
public static String computeHmacSha1(String value, @NonNull String keyString) { try { SecretKeySpec key = new SecretKeySpec((keyString).getBytes("UTF-8"), "HmacSHA1"); Mac mac = Mac.getInstance("HmacSHA1"); mac.init(key); byte[] bytes = mac.doFinal(value.getBytes("UTF-8")); return convToHex(bytes); } catch (NoSuchAlgorithmException e) { Logger.getInstance() .e(TAG, e); } catch (UnsupportedEncodingException e) { Logger.getInstance() .e(TAG, e); } catch (InvalidKeyException e) { Logger.getInstance() .e(TAG, e); } return ""; }
private Observable<Boolean> checkMd5AndMoveFileToRightPlace(Download download) { return Observable.fromCallable(() -> { for (final FileToDownload fileToDownload : download.getFilesToDownload()) { fileToDownload.setFileName(fileToDownload.getFileName() .replace(".temp", "")); if (!TextUtils.isEmpty(fileToDownload.getMd5())) { if (!TextUtils.equals(AptoideUtils.AlgorithmU.computeMd5( new File(genericPath + fileToDownload.getFileName())), fileToDownload.getMd5())) { return false; } } String newFilePath = getFilePathFromFileType(fileToDownload); fileUtils.copyFile(genericPath, newFilePath, fileToDownload.getFileName()); fileToDownload.setPath(newFilePath); } return true; }); }
public Installed(@NonNull PackageInfo packageInfo, @Nullable String storeName, PackageManager packageManager) { setIcon(AptoideUtils.SystemU.getApkIconPath(packageInfo)); setName(AptoideUtils.SystemU.getApkLabel(packageInfo, packageManager)); setPackageName(packageInfo.packageName); setVersionCode(packageInfo.versionCode); setVersionName(packageInfo.versionName); setStoreName(storeName); this.packageAndVersionCode = packageInfo.packageName + packageInfo.versionCode; setSystemApp((packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0); if (packageInfo.signatures != null && packageInfo.signatures.length > 0) { setSignature( AptoideUtils.AlgorithmU.computeSha1WithColon(packageInfo.signatures[0].toByteArray())); } setStatus(STATUS_COMPLETED); setType(TYPE_UNKNOWN); }
public static String computeSha1WithColon(byte[] bytes) { return convToHexWithColon(computeSha1(bytes)).toUpperCase(Locale.ENGLISH); }
public static String computeSha1(String text) { try { return convToHex(computeSha1(text.getBytes("iso-8859-1"))); } catch (UnsupportedEncodingException e) { Logger.getInstance() .e(TAG, "computeSha1(String)", e); } return ""; }