SSLCrypto.cs 1017 B

12345678910111213141516171819202122232425262728293031323334353637
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Security.Cryptography.X509Certificates;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace Server.lib
  9. {
  10. class SSLCrypto
  11. {
  12. public static void CreateSelfSignedCert()
  13. {
  14. byte[] c = SelfSignedCertificate.CreateSelfSignCertificatePfx(
  15. "CN=brdk.nl", //host name
  16. DateTime.Parse("2015-01-01"), //not valid before
  17. DateTime.Parse("2025-01-01"), //not valid after
  18. "jancoow"); //password to encrypt key file
  19. using (BinaryWriter binWriter = new BinaryWriter(
  20. File.Open(@"testcert.pfx", FileMode.Create)))
  21. {
  22. binWriter.Write(c);
  23. }
  24. }
  25. public static X509Certificate LoadCert()
  26. {
  27. X509Certificate cert = new X509Certificate2(
  28. @"testcert.pfx",
  29. "jancoow");
  30. return cert;
  31. }
  32. }
  33. }