本文整理汇总了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;
}
}