.NET Android 签名验证工具

作者: 2b75747cf703 | 来源:发表于2016-04-26 10:56 被阅读166次
    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);
                    };
                }
            }
        }
    }
    

    相关文章

      网友评论

        本文标题:.NET Android 签名验证工具

        本文链接:https://www.haomeiwen.com/subject/emmqrttx.html