WEB开发网
开发学院手机开发Android 开发 android怎样获取应用签名信息 阅读

android怎样获取应用签名信息

 2012-11-27 14:26:08 来源:WEB开发网   
核心提示: public void getSingInfo() {try {PackageInfo packageInfo = getPackageManager().getPackageInfo("com.example.yao", PackageManager.GET_SIGNATURES);Signat

 public void getSingInfo() {
try {
PackageInfo packageInfo = getPackageManager().getPackageInfo(
"com.example.yao", PackageManager.GET_SIGNATURES);
Signature[] signs = packageInfo.signatures;
Signature sign = signs[0];
parseSignature(sign.toByteArray());
} catch (Exception e) {
e.printStackTrace();
}
}

public void parseSignature(byte[] signature) {
try {
CertificateFactory certFactory = CertificateFactory
.getInstance("X.509");
X509Certificate cert = (X509Certificate) certFactory
.generateCertificate(new ByteArrayInputStream(signature));
String pubKey = cert.getPublicKey().toString();
String signNumber = cert.getSerialNumber().toString();

System.out.println("pubKey:" + pubKey);
System.out.println("signNumber:" + signNumber);
} catch (CertificateException e) {
e.printStackTrace();
}
}

Tags:android 怎样 获取

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接