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