SSLCrypto.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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 FietsLibrary
  9. {
  10. public class SSLCrypto
  11. {
  12. public static void CreateSelfSignedCert()
  13. {
  14. if (!File.Exists("testcert.pfx"))
  15. {
  16. byte[] c = SelfSignedCertificate.CreateSelfSignCertificatePfx(
  17. "CN=brdk.nl", //host name
  18. DateTime.Parse("2015-01-01"), //not valid before
  19. DateTime.Parse("2025-01-01"), //not valid after
  20. "jancoow"); //password to encrypt key file
  21. using (BinaryWriter binWriter = new BinaryWriter(
  22. File.Open(@"testcert.pfx", FileMode.Create)))
  23. {
  24. binWriter.Write(c);
  25. }
  26. }
  27. }
  28. public static X509Certificate LoadCert()
  29. {
  30. X509Certificate cert = new X509Certificate2(
  31. @"testcert.pfx",
  32. "jancoow");
  33. return cert;
  34. }
  35. }
  36. }