Skip to content

Commit

Permalink
Fix running on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
kev committed Nov 1, 2023
1 parent d750f3c commit bc6b852
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/SwapHunter/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,16 @@ public static X509Certificate2Collection GetCerts(string certPath, string keyPat
using StreamReader streamReader = new(keyPath);

var base64 = new StringBuilder(streamReader.ReadToEnd())
.Replace("-----BEGIN PRIVATE KEY-----", string.Empty)
.Replace("-----END PRIVATE KEY-----", string.Empty)
.Replace("-----BEGIN RSA PRIVATE KEY-----", string.Empty)
.Replace("-----END RSA PRIVATE KEY-----", string.Empty)
.Replace(Environment.NewLine, string.Empty)
.Replace("\r\n", string.Empty)
.ToString();

using var rsa = RSA.Create();
rsa.ImportRSAPrivateKey(Convert.FromBase64String(base64), out _);
rsa.ImportPkcs8PrivateKey(Convert.FromBase64String(base64), out _);

using var certWithKey = cert.CopyWithPrivateKey(rsa);
var ephemeralCert = new X509Certificate2(certWithKey.Export(X509ContentType.Pkcs12));
Expand Down

0 comments on commit bc6b852

Please sign in to comment.