Obtain the signature Public Key

Source: Internet
Author: User

tag: Android

Public class signinfo {public static final string tag = "signinfo";/*** obtain the signature public key ** @ Param mcontext * @ return */protected static string getsigninfo (context mcontext) {string signcode = ""; try {packageinfo = mcontext. getpackagemanager (). getpackageinfo (mcontext. getpackagename (), packagemanager. get_signatures); signature [] Signs = packageinfo. signatures; signature sign = signs [0]; signcode = parsesignature (sign. tobytearray (); signcode = signcode. tolowercase ();} catch (exception e) {debugutil. E (TAG, E. getmessage ();} return signcode;} protected static string parsesignature (byte [] signature) {string Sign = ""; try {certificatefactory certfactory = certificatefactory. getinstance ("X.509"); x509certificate Cert = (x509certificate) certfactory. generatecertificate (New bytearrayinputstream (Signature); string pubkey = cert. getpublickey (). tostring (); string Ss = substring (pubkey); SS = ss. replace (",", ""); SS = ss. tolowercase (); int AA = ss. indexof ("modulus"); int BB = ss. indexof ("publicexponent"); Sign = ss. substring (AA + 8, BB);} catch (certificateexception e) {debugutil. E (TAG, E. getmessage ();} return sign;} public static string substring (string sub) {pattern pp = pattern. compile ("\ s * | \ t | \ r | \ n"); matcher Mm = pp. matcher (sub); Return mm. replaceall ("");}}

Obtain the signature Public Key

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.