web后台解析apk获取信息

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.math.BigInteger;
import java.security.MessageDigest;

import org.apache.commons.codec.binary.Hex;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.web.multipart.MultipartFile;

/**
 * 此工具类依赖commons-codec
 * //https://mvnrepository.com/artifact/commons-codec/commons-codec/1.11
 * compile ('commons-codec:commons-codec:1.11')
 */

public class Md5CaculateUtil {

    /**
     * 获取一个文件的md5值(可处理大文件)
     *
     * @return md5 value
     */
    public static String getMD5(File file) {
        FileInputStream fileInputStream = null;
        try {
            MessageDigest MD5 = MessageDigest.getInstance("MD5");
            fileInputStream = new FileInputStream(file);
            byte[] buffer = new byte[8192];
            int length;
            while ((length = fileInputStream.read(buffer)) != -1) {
                MD5.update(buffer, 0, length);
            }
            return new String(Hex.encodeHex(MD5.digest()));
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        } finally {
            try {
                if (fileInputStream != null) {
                    fileInputStream.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    /**
     * 获取上传文件的md5
     *
     * @param file
     * @return
     * @throws IOException
     */
    public static String getMD5(MultipartFile file) {

        try {
            byte[] uploadBytes = file.getBytes();
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            byte[] digest = md5.digest(uploadBytes);
            String hashString = new BigInteger(1, digest).toString(16);
            return hashString;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;

    }

    /**
     * 求一个字符串的md5值
     *
     * @param target 字符串
     * @return md5 value
     */
    public static String MD5(String target) {
        return DigestUtils.md5Hex(target);
    }

    public static void main(String[] args) {
        long beginTime = System.currentTimeMillis();
        File file = new File("D:/1/pdi-ce-7.0.0.0-24.zip");
        String md5 = getMD5(file);
        long endTime = System.currentTimeMillis();
        System.out.println("MD5:" + md5 + "\n 耗时:" + ((endTime - beginTime) / 1000) + "s");
    }
}

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
解析 APK 并获取其信息和公钥,可以使用 Android SDK 中的 aapt 工具和 .NET 的 Process 类来执行命令并获取输出。下面是一个示例 C# 代码: ```csharp using System; using System.Diagnostics; namespace ApkParser { class Program { static void Main(string[] args) { string apkPath = "path/to/apk/file.apk"; string aaptPath = "path/to/aapt.exe"; // 执行命令获取 APK 信息 var processStartInfo = new ProcessStartInfo { FileName = aaptPath, Arguments = $"d badging \"{apkPath}\"", RedirectStandardOutput = true, UseShellExecute = false, CreateNoWindow = true }; using (var process = Process.Start(processStartInfo)) { process.WaitForExit(); var output = process.StandardOutput.ReadToEnd(); // 解析输出获取 APK 信息 var packageName = GetValueFromOutput(output, "package: name='", "'"); var versionCode = GetValueFromOutput(output, "versionCode='", "'"); var versionName = GetValueFromOutput(output, "versionName='", "'"); var publicKey = GetValueFromOutput(output, "publicKey='", "'"); Console.WriteLine($"Package Name: {packageName}"); Console.WriteLine($"Version Code: {versionCode}"); Console.WriteLine($"Version Name: {versionName}"); Console.WriteLine($"Public Key: {publicKey}"); } } static string GetValueFromOutput(string output, string startTag, string endTag) { var startIndex = output.IndexOf(startTag) + startTag.Length; var endIndex = output.IndexOf(endTag, startIndex); return output.Substring(startIndex, endIndex - startIndex); } } } ``` 在代码中,我们首先指定 APK 文件路径和 aapt 工具路径,然后使用 Process 类执行命令获取 APK 信息,并解析输出获取信息和公钥。最后将结果输出到控制台。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值