Home>

1. The java code is as follows:

private byte [] getsign (context context) {
 packagemanager pm=context.getpackagemanager ();
 list<packageinfo>apps=pm
  .getinstalledpackages (packagemanager.get_signatures);
 iterator<packageinfo>iter=apps.iterator ();
 while (iter.hasnext ()) {
  packageinfo info=iter.next ();
  string packagename=info.packagename;
  //Get signature by package name
  if (packagename.equals ("com.test.test")) {
  return info.signatures [0] .tobytearray ();
  }
 }
 return null;
}

2. The java code is as follows:

public static string getpublickey (byte [] signature) {
try {
  certificatefactory certfactory=certificatefactory
   .getinstance ("x.509");
  x509certificate cert=(x509certificate) certfactory
   .generatecertificate (new bytearrayinputstream (signature));
  string publickey=cert.getpublickey (). tostring ();
  publickey=publickey.substring (publickey.indexof ("modulus:") + 9,   publickey.indexof ("\ n", publickey.indexof ("modulus:")));
  log.d ("track", publickey);
  return publickey;
 } catch (certificateexception e) {
  e.printstacktrace ();
 }
 return null;
}
  • Previous JS implements black style web page TAB tab effect code
  • Next Android call stack trace instance analysis