private void DrawSecurityTab()
        {
            s_xmlPath        = PathField(xmlPathGUI, s_xmlPath, false);
            s_publicKeyPath  = PathField(publicKeyPathGUI, s_publicKeyPath, false);
            s_PrivateKeyPath = PathField(privateKeyPathGUI, s_PrivateKeyPath, false);

            if (GUILayout.Button("Sign XML", GUILayout.Height(35f)))
            {
                s_xmlPath        = s_xmlPath.Trim();
                s_PrivateKeyPath = s_PrivateKeyPath.Trim();

                if (s_xmlPath.Length == 0 || s_PrivateKeyPath.Length == 0)
                {
                    return;
                }

                XMLSigner.SignXMLFile(s_xmlPath, File.ReadAllText(s_PrivateKeyPath));
            }

            if (GUILayout.Button("Verify XML", GUILayout.Height(35f)))
            {
                s_xmlPath       = s_xmlPath.Trim();
                s_publicKeyPath = s_publicKeyPath.Trim();

                if (s_xmlPath.Length == 0 || s_publicKeyPath.Length == 0)
                {
                    return;
                }

                Debug.Log("Is genuine: " + XMLSigner.VerifyXMLFile(s_xmlPath, File.ReadAllText(s_publicKeyPath)));
            }

            GUILayout.Space(10f);

            EditorGUILayout.HelpBox("Store your private key in a safe location and don't share it with unknown parties!", MessageType.Warning);

            if (GUILayout.Button("Create RSA Key Pair", GUILayout.Height(35f)))
            {
                string selectedPath = EditorUtility.OpenFolderPanel("Create keys at", "", "");
                if (string.IsNullOrEmpty(selectedPath) || !Directory.Exists(selectedPath))
                {
                    return;
                }

                string publicKey, privateKey;
                SecurityUtils.CreateRSAKeyPair(out publicKey, out privateKey);

                File.WriteAllText(Path.Combine(selectedPath, "public.key"), publicKey);
                File.WriteAllText(Path.Combine(selectedPath, "private.key"), privateKey);

                AssetDatabase.Refresh();
            }

            if (GUILayout.Button("Help", GUILayout.Height(25f)))
            {
                Application.OpenURL("https://github.com/yasirkula/SimplePatchTool/wiki/Signing-&-Verifying-Patches#built-in-method");
            }
        }
Esempio n. 2
0
        private static void GenerateRSAKeyPair()
        {
            string privateKey, publicKey;

            SecurityUtils.CreateRSAKeyPair(out publicKey, out privateKey);

            File.WriteAllText(GetArgument("private"), privateKey);
            File.WriteAllText(GetArgument("public"), publicKey);
        }
        private void DrawSecurityTab()
        {
            s_xmlPath        = PathField("XML file: ", s_xmlPath, false);
            s_publicKeyPath  = PathField("Public RSA key: ", s_publicKeyPath, false);
            s_PrivateKeyPath = PathField("Private RSA key: ", s_PrivateKeyPath, false);

            if (GUILayout.Button("Sign XML", GUILayout.Height(35f)))
            {
                s_xmlPath        = s_xmlPath.Trim();
                s_PrivateKeyPath = s_PrivateKeyPath.Trim();

                if (string.IsNullOrEmpty(s_xmlPath) || string.IsNullOrEmpty(s_PrivateKeyPath))
                {
                    return;
                }

                XMLSigner.SignXMLFile(s_xmlPath, File.ReadAllText(s_PrivateKeyPath));
            }

            if (GUILayout.Button("Verify XML", GUILayout.Height(35f)))
            {
                s_xmlPath       = s_xmlPath.Trim();
                s_publicKeyPath = s_publicKeyPath.Trim();

                if (string.IsNullOrEmpty(s_xmlPath) || string.IsNullOrEmpty(s_publicKeyPath))
                {
                    return;
                }

                Debug.Log("Is genuine: " + XMLSigner.VerifyXMLFile(s_xmlPath, File.ReadAllText(s_publicKeyPath)));
            }

            GUILayout.Space(10f);

            EditorGUILayout.HelpBox("Store your private key in a safe location and don't share it with unknown parties!", MessageType.Warning);

            if (GUILayout.Button("Create RSA Key Pair", GUILayout.Height(35f)))
            {
                string selectedPath = EditorUtility.OpenFolderPanel("Create keys at", "", "");
                if (string.IsNullOrEmpty(selectedPath) || !Directory.Exists(selectedPath))
                {
                    return;
                }

                string publicKey, privateKey;
                SecurityUtils.CreateRSAKeyPair(out publicKey, out privateKey);

                File.WriteAllText(Path.Combine(selectedPath, "rsa_public.bytes"), publicKey);
                File.WriteAllText(Path.Combine(selectedPath, "rsa_private.bytes"), privateKey);

                AssetDatabase.Refresh();
            }
        }