工具下载地址
签名工具下载地址:
https://developers.weixin.qq.com/doc/oplatform/Downloads/Android_Resource.html
什么时候使用呢?
当你去申请开发者账号的时候,如果是android应用,则需要你填写包名和签名。
它到底做了什么呢?
我们把这个apk下载下来吧,然后反编译一下。
点击按钮,调用签名方法
MainAct.this.getSign(str);
获取签名
Signature[] arrayOfSignature = getRawSignature((Context)this, paramString);
paramString这个是包名
如何获取到签名的呢?
PackageManager packageManager = paramContext.getPackageManager();
return ((PackageInfo)packageManager).signatures;
这两行是主要代码了
再回到前面获取的地方如何处理?
stdout(MD5.getMessageDigest(arrayOfSignature[b].toByteArray()));
转成MD5值,然后输出,就如上图所示了。
完整的反编译代码
package com.tencent.mm.openapi;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.Signature;
import android.os.Bundle;
import android.text.ClipboardManager;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MainAct extends Activity {
private Button copyBtn;
private TextView errorTv;
private Button getBtn;
private EditText pkgNameEt;
private TextView resultTv;
private void errout(String paramString) {
this.errorTv.append(String.valueOf(paramString) + "\n");
}
private Signature[] getRawSignature(Context paramContext, String paramString) {
Context context = null;
if (paramString == null || paramString.length() == 0) {
errout("getSignature, packageName is null");
return (Signature[])context;
}
PackageManager packageManager = paramContext.getPackageManager();
try {
PackageInfo packageInfo = packageManager.getPackageInfo(paramString, 64);
if (packageInfo == null) {
errout("info is null, packageName = " + paramString);
return (Signature[])context;
}
} catch (android.content.pm.PackageManager.NameNotFoundException nameNotFoundException) {
errout("NameNotFoundException");
return (Signature[])context;
}
return ((PackageInfo)packageManager).signatures;
}
private void getSign(String paramString) {
Signature[] arrayOfSignature = getRawSignature((Context)this, paramString);
if (arrayOfSignature == null || arrayOfSignature.length == 0) {
errout("signs is null");
return;
}
int i = arrayOfSignature.length;
byte b = 0;
while (true) {
if (b < i) {
stdout(MD5.getMessageDigest(arrayOfSignature[b].toByteArray()));
b++;
continue;
}
return;
}
}
private void showDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder((Context)this);
builder.setCancelable(false);
builder.setTitle(2130968584).setMessage(2130968585);
builder.setPositiveButton(2130968582, null);
builder.setNegativeButton(2130968583, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface param1DialogInterface, int param1Int) {
MainAct.this.finish();
}
});
builder.show();
}
private void stdout(String paramString) {
this.resultTv.append(String.valueOf(paramString) + "\n");
this.copyBtn.setVisibility(0);
}
public void onCreate(Bundle paramBundle) {
super.onCreate(paramBundle);
setContentView(2130903040);
this.pkgNameEt = (EditText)findViewById(2131034112);
this.resultTv = (TextView)findViewById(2131034114);
this.errorTv = (TextView)findViewById(2131034115);
this.getBtn = (Button)findViewById(2131034113);
this.getBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View param1View) {
MainAct.this.resultTv.setText("");
MainAct.this.errorTv.setText("");
MainAct.this.copyBtn.setVisibility(8);
String str = MainAct.this.pkgNameEt.getText().toString();
if (str != null && str.length() > 0)
MainAct.this.getSign(str);
}
});
this.copyBtn = (Button)findViewById(2131034116);
this.copyBtn.setVisibility(8);
this.copyBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View param1View) {
((ClipboardManager)MainAct.this.getSystemService("clipboard")).setText(MainAct.this.resultTv.getText().toString().trim());
Toast.makeText((Context)MainAct.this, 2130968581, 1).show();
}
});
showDialog();
}
}
MD5.java
package com.tencent.mm.openapi;
import java.security.MessageDigest;
public final class MD5 {
public static final String getMessageDigest(byte[] paramArrayOfbyte) {
// Byte code:
// 0: bipush #16
// 2: newarray char
// 4: astore_1
// 5: aload_1
// 6: dup
// 7: iconst_0
// 8: ldc 48
// 10: castore
// 11: dup
// 12: iconst_1
// 13: ldc 49
// 15: castore
// 16: dup
// 17: iconst_2
// 18: ldc 50
// 20: castore
// 21: dup
// 22: iconst_3
// 23: ldc 51
// 25: castore
// 26: dup
// 27: iconst_4
// 28: ldc 52
// 30: castore
// 31: dup
// 32: iconst_5
// 33: ldc 53
// 35: castore
// 36: dup
// 37: bipush #6
// 39: ldc 54
// 41: castore
// 42: dup
// 43: bipush #7
// 45: ldc 55
// 47: castore
// 48: dup
// 49: bipush #8
// 51: ldc 56
// 53: castore
// 54: dup
// 55: bipush #9
// 57: ldc 57
// 59: castore
// 60: dup
// 61: bipush #10
// 63: ldc 97
// 65: castore
// 66: dup
// 67: bipush #11
// 69: ldc 98
// 71: castore
// 72: dup
// 73: bipush #12
// 75: ldc 99
// 77: castore
// 78: dup
// 79: bipush #13
// 81: ldc 100
// 83: castore
// 84: dup
// 85: bipush #14
// 87: ldc 101
// 89: castore
// 90: dup
// 91: bipush #15
// 93: ldc 102
// 95: castore
// 96: pop
// 97: ldc 'MD5'
// 99: invokestatic getInstance : (Ljava/lang/String;)Ljava/security/MessageDigest;
// 102: astore_2
// 103: aload_2
// 104: aload_0
// 105: invokevirtual update : ([B)V
// 108: aload_2
// 109: invokevirtual digest : ()[B
// 112: astore_0
// 113: aload_0
// 114: arraylength
// 115: istore_3
// 116: iload_3
// 117: iconst_2
// 118: imul
// 119: newarray char
// 121: astore_2
// 122: iconst_0
// 123: istore #4
// 125: iconst_0
// 126: istore #5
// 128: iload #4
// 130: iload_3
// 131: if_icmplt -> 145
// 134: new java/lang/String
// 137: astore_0
// 138: aload_0
// 139: aload_2
// 140: invokespecial <init> : ([C)V
// 143: aload_0
// 144: areturn
// 145: aload_0
// 146: iload #4
// 148: baload
// 149: istore #6
// 151: iload #5
// 153: iconst_1
// 154: iadd
// 155: istore #7
// 157: aload_2
// 158: iload #5
// 160: aload_1
// 161: iload #6
// 163: iconst_4
// 164: iushr
// 165: bipush #15
// 167: iand
// 168: caload
// 169: i2c
// 170: castore
// 171: iload #7
// 173: iconst_1
// 174: iadd
// 175: istore #5
// 177: aload_2
// 178: iload #7
// 180: aload_1
// 181: iload #6
// 183: bipush #15
// 185: iand
// 186: caload
// 187: i2c
// 188: castore
// 189: iinc #4, 1
// 192: goto -> 128
// 195: astore_0
// 196: aconst_null
// 197: astore_0
// 198: goto -> 143
// Exception table:
// from to target type
// 97 122 195 java/lang/Exception
// 134 143 195 java/lang/Exception
}
public static final byte[] getRawDigest(byte[] paramArrayOfbyte) {
try {
MessageDigest messageDigest = MessageDigest.getInstance("MD5");
messageDigest.update(paramArrayOfbyte);
paramArrayOfbyte = messageDigest.digest();
} catch (Exception exception) {
exception = null;
}
return (byte[])exception;
}
}