码迷,mamicode.com
首页 > 移动开发 > 详细

APP获取证书签名指纹

时间:2019-04-09 20:21:03      阅读:356      评论:0      收藏:0      [点我收藏+]

标签:account   取证   amp   ase   ESS   nsstring   ssg   sig   指定   

Android:

    public static String getSignatureSHA1(Context context) {
        String sign = null;
        try {
            // 通过包管理器获得指定包名包含签名的包信息
            @SuppressLint("PackageManagerGetSignatures")
            PackageInfo packageInfo = context.getPackageManager()
                    .getPackageInfo(context.getPackageName(), PackageManager.GET_SIGNATURES);
            // 通过返回的包信息获得签名数组
            Signature[] signatures = packageInfo.signatures;
            sign = getSHA1FromSignature(signatures[0].toByteArray());
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }

        return sign;
    }

 

iOS:

+ (NSString *)bundleSeedID {
    NSDictionary *query = [NSDictionary dictionaryWithObjectsAndKeys:
                           (__bridge id)kSecClassGenericPassword, (__bridge id)kSecClass,
                           @"bundleSeedID", (__bridge id)kSecAttrAccount,
                           @"", (__bridge id)kSecAttrService,
                           (id)kCFBooleanTrue, (__bridge id)kSecReturnAttributes,
                           nil];
    CFDictionaryRef result = nil;
    OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef)query, (CFTypeRef *)&result);
    if (status == errSecItemNotFound)
        status = SecItemAdd((__bridge CFDictionaryRef)query, (CFTypeRef *)&result);
    if (status != errSecSuccess)
        return nil;
    NSString *accessGroup = [(__bridge NSDictionary *)result objectForKey:(__bridge id)kSecAttrAccessGroup];
    NSArray *components = [accessGroup componentsSeparatedByString:@"."];
    NSString *bundleSeedID = [[components objectEnumerator] nextObject];
    CFRelease(result);
    return bundleSeedID;
}

 

APP获取证书签名指纹

标签:account   取证   amp   ase   ESS   nsstring   ssg   sig   指定   

原文地址:https://www.cnblogs.com/qiyer/p/10679153.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!