本文整理匯總了Java中android.content.pm.Signature.toByteArray方法的典型用法代碼示例。如果您正苦於以下問題:Java Signature.toByteArray方法的具體用法?Java Signature.toByteArray怎麽用?Java Signature.toByteArray使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.content.pm.Signature
的用法示例。
在下文中一共展示了Signature.toByteArray方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: isDebuggable
import android.content.pm.Signature; //導入方法依賴的package包/類
/**
* 檢測當前應用是否是Debug版本
*
* @param ctx
* @return
*/
public static boolean isDebuggable(Context ctx) {
boolean debuggable = false;
try {
PackageInfo pinfo = ctx.getPackageManager().getPackageInfo(ctx.getPackageName(), PackageManager.GET_SIGNATURES);
Signature signatures[] = pinfo.signatures;
for (Signature signature : signatures) {
CertificateFactory cf = CertificateFactory.getInstance("X.509");
ByteArrayInputStream stream = new ByteArrayInputStream(signature.toByteArray());
X509Certificate cert = (X509Certificate) cf
.generateCertificate(stream);
debuggable = cert.getSubjectX500Principal().equals(DEBUG_DN);
if (debuggable)
break;
}
} catch (NameNotFoundException | CertificateException e) {
}
return debuggable;
}
示例2: getSign
import android.content.pm.Signature; //導入方法依賴的package包/類
public static String getSign(Context context, String pkgName) {
try {
PackageInfo packageInfo = context.getPackageManager().getPackageInfo(pkgName, 64);
for (Signature toByteArray : packageInfo.signatures) {
byte[] str = toByteArray.toByteArray();
if (str != null) {
return MD5.hexdigest(str);
}
}
return null;
} catch (NameNotFoundException e) {
return null;
}
}
示例3: getSignature
import android.content.pm.Signature; //導入方法依賴的package包/類
public static byte[] getSignature(Context context) {
PackageInfo packageInfo = null;
try {
packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_SIGNATURES);
} catch (PackageManager.NameNotFoundException e) {
L.e(e);
}
if (packageInfo == null || packageInfo.signatures == null)
return null;
Signature signature = packageInfo.signatures[0];
return signature.toByteArray();
}
示例4: signatureDigest
import android.content.pm.Signature; //導入方法依賴的package包/類
private static String signatureDigest(Signature sig) {
byte[] signature = sig.toByteArray();
try {
MessageDigest md = MessageDigest.getInstance("SHA1");
byte[] digest = md.digest(signature);
return BaseEncoding.base16().lowerCase().encode(digest);
} catch (NoSuchAlgorithmException e) {
return null;
}
}