新浪微博 登陆  注册   设为首页 加入收藏

学PHP >> Android教程 >> android 获取应用证书及签名信息

android 获取应用证书及签名信息

查看次数24489 发表时间2012-09-04 15:12:01

private String[] getCertMsg(String packageName){
String[] certMsg = new String[2];
PackageInfo pis;
try {

pis = mContext.getPackageManager().getPackageInfo(packageName, PackageManager.GET_SIGNATURES);

Signature[] sigs = pis.signatures;    //签名

CertificateFactory certFactory = CertificateFactory.getInstance("X.509");  

//获取证书

X509Certificate cert = (X509Certificate) certFactory.generateCertificate(

new ByteArrayInputStream(sigs[0].toByteArray()));

//获取证书发行者   可根据证书发行者来判断该应用是否被二次打包(被破解的应用重新打包后,签名与原包一定不同,据此可以判断出该应用是否被人做过改动)

certMsg[0] = cert.getIssuerDN().toString();
certMsg[1] = cert.getSubjectDN().toString();
DebugUtil.i("IssuerDN: " + certMsg[0] + "  SubjectDN: " + certMsg[1]);
} catch (CertificateException e) {
// TODO Auto-generated catch block
DebugUtil.e("CertificateException" + e.getMessage());
} catch (Exception e) {
// TODO Auto-generated catch block
DebugUtil.e("Exception: " + e.getMessage());
}
return certMsg;
}
(转发请注明转自:学PHP)    


  相关推荐



1楼 Mildred说: 2016-12-12 07:20:44
Wow! Talk about a posting knocnikg my socks off!

  发表评论
昵称:
(不超过20个字符或10个汉字)
内容: