Unity通过代码获取SHA1

image.png
#if UNITY_EDITOR
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.IO;
using System.Runtime.CompilerServices;

public class ShowSHA1
{
    // user.keystore的路径
    private static string KeyStoreFilePath => "Assets/user.keystore";
    // keystore的密码
    private static string Password => "password123";
    private static string KeystorePath => Path.Join(Path.GetDirectoryName(Application.dataPath), KeyStoreFilePath);

    [MenuItem("Tools/显示SHA1")]
    private static void Show()
    {
        var args = $"keytool -list -v -keystore {KeystorePath}  -storepass {Password}";

        System.Diagnostics.Process p = new System.Diagnostics.Process();
        //设置要启动的应用程序
        p.StartInfo.FileName = "cmd.exe";
        //是否使用操作系统shell启动
        p.StartInfo.UseShellExecute = false;
        // 接受来自调用程序的输入信息
        p.StartInfo.RedirectStandardInput = true;
        //输出信息
        p.StartInfo.RedirectStandardOutput = true;
        // 输出错误
        p.StartInfo.RedirectStandardError = true;
        //不显示程序窗口
        p.StartInfo.CreateNoWindow = true;
        //启动程序
        p.Start();

        //向cmd窗口发送输入信息
        p.StandardInput.WriteLine(args + "&exit");

        p.StandardInput.AutoFlush = true;

        //获取输出信息
        string strOuput = p.StandardOutput.ReadToEnd();
        //等待程序执行完退出进程
        p.WaitForExit();
        p.Close();

        Debug.Log(strOuput);
    }
}
#endif
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容