2020-2-8 seo達(dá)人
閑著沒事兒寫了個(gè)小 demo ,獲取手機(jī)上已安裝應(yīng)用信息,系統(tǒng)應(yīng)用和 非系統(tǒng)應(yīng)用
MD5 SHA1 SHA256 簽名信息 點(diǎn)擊簽名信息可復(fù)制到剪切板,
GitHub:https://github.com/sunan-n/GetAppInfo
如下圖:
<span style="white-space:pre;"> </span>主要就是這個(gè)方法,傳參數(shù)進(jìn)來獲取相應(yīng)的簽名類型 信息<br />
public static String getSignaturesInfo(Context context, String packageName, String tpye) {<br />
// //獲取包管理器<br />
PackageManager pm = context.getPackageManager();<br />
//返回包括在包中的簽名信息<br />
int flags = PackageManager.GET_SIGNATURES;<br />
PackageInfo packageInfo = null;<br />
try {<br />
//獲得包的所有內(nèi)容信息類<br />
packageInfo = pm.getPackageInfo(packageName, flags);<br />
} catch (PackageManager.NameNotFoundException e) {<br />
e.printStackTrace();<br />
}<br />
//簽名信息<br />
Signature[] signatures = packageInfo.signatures;<br />
byte[] cert = signatures[0].toByteArray();<br />
//將簽名轉(zhuǎn)換為字節(jié)數(shù)組流<br />
InputStream input = new ByteArrayInputStream(cert);<br />
//證書工廠類,這個(gè)類實(shí)現(xiàn)了出廠合格證算法的功能<br />
CertificateFactory cf = null;<br />
try {<br />
cf = CertificateFactory.getInstance("X509");<br />
} catch (CertificateException e) {<br />
e.printStackTrace();<br />
}<br />
//X509證書,X.509是一種非常通用的證書格式<br />
X509Certificate c = null;<br />
try {<br />
c = (X509Certificate) cf.generateCertificate(input);<br />
} catch (CertificateException e) {<br />
e.printStackTrace();<br />
}<br />
String hexString = null;<br />
try {<br />
//加密算法的類,這里的參數(shù)可以使MD4,MD5等加密算法<br />
// MessageDigest md = MessageDigest.getInstance("SHA1");<br />
MessageDigest md = MessageDigest.getInstance(tpye);<br />
//獲得公鑰<br />
byte[] publicKey = md.digest(c.getEncoded());<br />
//字節(jié)到十六進(jìn)制的格式轉(zhuǎn)換<br />
hexString = byte2HexFormatted(publicKey);<br />
} catch (NoSuchAlgorithmException e1) {<br />
e1.printStackTrace();<br />
} catch (CertificateEncodingException e) {<br />
e.printStackTrace();<br />
}<br />
return hexString;<br />
}<br />
<br />
藍(lán)藍(lán)設(shè)計(jì)的小編 http://www.wnxcall.com