.NET Android 签名验证工具

763 查看

using System;
using System.Diagnostics;
using System.IO;
using System.Windows.Forms;
using Microsoft.Win32;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        private string javaHome;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            string JRE_REGISTRY_KEY = @"HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment";

            string jreVersion = (string)Registry.GetValue(JRE_REGISTRY_KEY, "CurrentVersion", null);
            string keyName = Path.Combine(JRE_REGISTRY_KEY, jreVersion);

            javaHome = (string)Registry.GetValue(keyName, "JavaHome", null);
        }

        private void Form1_DragEnter(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
                e.Effect = DragDropEffects.Copy;
        }

        private void Form1_DragDrop(object sender, DragEventArgs e)
        {
            string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
            foreach (string file in files)
            {
                ProcessStartInfo startInfo = new ProcessStartInfo();
                startInfo.WorkingDirectory = "";
                startInfo.FileName = javaHome + "\\bin\\keytool.exe";
                startInfo.Arguments = "-printcert -rfc -jarfile \"" + file + "\"";
                startInfo.UseShellExecute = false;
                startInfo.RedirectStandardOutput = true;
                startInfo.RedirectStandardError = true;
                startInfo.CreateNoWindow = true;


                Process process = Process.Start(startInfo);
                process.EnableRaisingEvents = true;
                process.Exited += delegate(object s, EventArgs eventArgs)
                {
                    string output = process.StandardOutput.ReadToEnd();
                    if (output != "")
                    {
                        if (output.Contains("证书所有者:"))
                        {
                            if (output.Contains("证书所有者: CN=Louis Lu, OU=Sinyee Inc, O=Sinyee Inc, L=FuZhou, ST=FuJian, C=CN"))
                                MessageBox.Show(Path.GetFileName(file) + " 证书正确", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            else
                                MessageBox.Show(Path.GetFileName(file) + " 证书错误", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        else
                            MessageBox.Show(output, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    string error = process.StandardError.ReadToEnd();
                    if (error != "")
                        MessageBox.Show(error, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                };
            }
        }
    }
}