Example #1
0
/// <summary>
/// Конвертируем JKS в P12
/// </summary>
/// <param name="pathJksFile"></param>
/// <param name="aliasName"></param>
        public static void ConvertJksInPkcs12(string pathJksFile, string aliasName)
        {
            Console.WriteLine("Данные для формирования -.p12 получены = ОК\n");
            var patchP12File = Path.ChangeExtension(pathJksFile, "p12");
            // Console.WriteLine($"echo {KeytoolPath} -importkeystore -srckeystore {pathJksFile} -destkeystore {patchP12File} -deststoretype PKCS12 -srcalias \"{aliasName}\" -srcstorepass {passwCert} -deststorepass {passwCert} -destkeypass {passwCert}");
            //выполняем скрипт powershell
            // var output = Execute.ExecuteExternal("pwsh", $"-c \"echo '{passwCert}' | {KeytoolPath} -list -v -keystore {NameFile(pathJksFile)}\"");
            var output = Execute.ExecuteExternal("pwsh", $"-c \"echo '{passwCert}' | {KeytoolPath} -importkeystore -srckeystore {pathJksFile} -destkeystore {patchP12File} -deststoretype PKCS12 -srcalias \"{aliasName}\" -srcstorepass {passwCert} -deststorepass {passwCert} -destkeypass {passwCert}");

            //Console.WriteLine("Тестовые данные. Файл должен быть тут: " + patchP12File + "\n");
            if (output.Contains("error"))
            {
                ConsoleHelper.ShowError(output);
            }
            else if (System.IO.File.Exists(patchP12File))
            {
                Console.WriteLine("Файл сертефиката -.p12 создан успешно = ОК\n");
                CertTool.pathP12File = patchP12File;
                CertTool.ConvertKeyPem();
            }
            else
            {
                Console.WriteLine("Неизвестная ошибка. Файл не создан. Начинай дебажить = FAIL\n");
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            //сделать обработку аргументов следующим обращом:
            //MyProgram.exe
            //      -j [pathJKS]
            //      -c [pathCRT]
            // ПОИЩИ ОБРАБОТКУ АРГУМЕНТОВ в C# КАК ДЕЛАЕТСЯ
            ConsoleHelper.SetDefaultColor();


            if (args.Length == 0)
            {
                ConsoleHelper.ShowHelp();
            }
            else
            {
                if (args[0] == "-j")
                {
                    string pathFile = args[1];
                    CertTool.passwCert = args[2]; //пароль
                    if (!System.IO.File.Exists(pathFile))
                    {
                        //если файл не существует то покажем ошибку
                        ConsoleHelper.ShowError("Указаного файла не существует!");
                        return;
                    }
                    CertTool.CreateCsr(pathFile);
                }
                else if (args[0] == "-c")
                {
                    string jksPathFile = args[1];
                    CertTool.passwCert = args[2];     //пароль
                    string newCrtPathFile = args[3];  //Присланный CRT для сверки и формирования ключа
                    string oldCsrPathFile = args[4];  //Старый CSR Для сверки
                    if (!System.IO.File.Exists(jksPathFile) || (!System.IO.File.Exists(oldCsrPathFile)) || (!System.IO.File.Exists(newCrtPathFile)))
                    {
                        //если файл не существует то покажем ошибку
                        ConsoleHelper.ShowError("Один или несколько файлов не найдены");
                        return;
                    }
                    CertTool.CreateNewKey(pathJksFile: jksPathFile, crtPathFile: newCrtPathFile, csrPathFile: oldCsrPathFile);
                }

                //Для теста
                else if (args[0] == "-crc")
                {
                    string oldCrtPathFile = args[1];
                    string newCrtPathFile = args[2];
                    Console.WriteLine(CertTool.CompareCRC(oldCrtPathFile));
                    Console.WriteLine(CertTool.CompareCRC(newCrtPathFile));
                    Console.WriteLine(CertTool.CompareCRC(oldCrtPathFile, newCrtPathFile));
                }
                else
                {
                    ConsoleHelper.ShowHelp();
                }
            }
        }
Example #3
0
        public static void CreateNewKey(string pathJksFile, string crtPathFile, string csrPathFile = null)
        {
            string compare = CertTool.CompareCRC(csrPathFile, crtPathFile);

            Console.WriteLine(compare);
            if (compare.Substring(0, 4) != "Ошибка сверки контрольных сумм.")
            {
                //получаем алиас из файла
                var aliasName = GetAliasKeyTool(pathJksFile);
                //генерируем P12 и остальное
                ConvertJksInPkcs12(pathJksFile, aliasName);
                CertTool.pathNewKeyP12(crtPathFile);
            }
        }