/
githubmirror
/
aspnetcore
Обзор
Документация
Войти
/
githubmirror
/
aspnetcore
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
eng/tools/RepoTasks/shared/CertificateGeneration/DevelopmentCertificate.cs
45 строк
2 KB
Javier Calvarro Nelson
[Templates] Generate single test HTTPS Certificate (#57431)
22 авг 2024, 01:34
Не верифицирован
22 авг 2024, 01:34
d65f5c4
Код
Авторство
О чём код?
// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.AspNetCore.Certificates.Generation; namespace RepoTasks; public readonly struct DevelopmentCertificate { public DevelopmentCertificate(string certificatePath, string certificatePassword, string certificateThumbprint) { CertificatePath = certificatePath; CertificatePassword = certificatePassword; CertificateThumbprint = certificateThumbprint; } public readonly string CertificatePath { get; } public readonly string CertificatePassword { get; } public readonly string CertificateThumbprint { get; } public static DevelopmentCertificate Create(string certificatePath) { var certificatePassword = ""; var certificateThumbprint = EnsureDevelopmentCertificates(certificatePath, certificatePassword); return new DevelopmentCertificate(certificatePath, certificatePassword, certificateThumbprint); } private static string EnsureDevelopmentCertificates(string certificatePath, string certificatePassword) { var now = DateTimeOffset.Now; var manager = CertificateManager.Instance; var certificate = manager.CreateAspNetCoreHttpsDevelopmentCertificate(now, now.AddYears(1)); var certificateThumbprint = certificate.Thumbprint; manager.ExportCertificate(certificate, path: certificatePath, includePrivateKey: true, certificatePassword, CertificateKeyExportFormat.Pfx); return certificateThumbprint; } }