Ejemplo n.º 1
0
 public static void GenerateNewKeyPair(string exportDirectoryPath)
 {
     try
     {
         int  keyPairType    = GetKeyPairType();
         bool validUserInput = FilePathValidation.GenerateKeyPair(exportDirectoryPath, keyPairType);
         if (!validUserInput)
         {
             return;
         }
         string publicKey, privateKey, publicKeyPath, privateKeyPath;
         if (keyPairType == 1)
         {
             (publicKey, privateKey)         = AsymmetricKeys.GenerateEncryptionKeyPair();
             (publicKeyPath, privateKeyPath) = AsymmetricKeys.ExportEncryptionKeyPair(exportDirectoryPath, publicKey, privateKey);
         }
         else
         {
             (publicKey, privateKey)         = AsymmetricKeys.GenerateSigningKeyPair();
             (publicKeyPath, privateKeyPath) = AsymmetricKeys.ExportSigningKeyPair(exportDirectoryPath, publicKey, privateKey);
         }
         DisplayKeyPair(publicKey, publicKeyPath, privateKeyPath);
     }
     catch (Exception ex) when(ExceptionFilters.FileAccess(ex))
     {
         Logging.LogException(ex.ToString(), Logging.Severity.Error);
         DisplayMessage.FilePathException(exportDirectoryPath, ex.GetType().Name, "Unable to export key pair.");
     }
 }