2
我正在使用此代码,但它显示了同一应用程序的哈希代码。 请帮我解决。从内存中安装的apk文件生成哈希
File file = new File(getApplicationContext().getPackageCodePath());
String outputTxt= "";
String hashcode = null;
try {
FileInputStream input = new FileInputStream(file);
ByteArrayOutputStream output = new ByteArrayOutputStream();
byte [] buffer = new byte [65536];
int l;
while ((l = input.read (buffer)) > 0)
output.write (buffer, 0, l);
input.close();
output.close();
byte [] data = output.toByteArray();
MessageDigest digest = MessageDigest.getInstance("SHA-1");
byte[] bytes = data;
digest.update(bytes, 0, bytes.length);
bytes = digest.digest();
StringBuilder sb = new StringBuilder();
for(byte b : bytes)
{
sb.append(String.format("%02X", b));
}
hashcode = sb.toString();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
现在我想读(假设它会被* .apk文件)我目前的Android应用程序的安装的应用程序文件,从文件中读取的字节数组,并产生散列值。
在此先感谢。