Created
July 12, 2024 20:47
-
-
Save Ilchert/b3199aac6eb4663ce8cb9a50a1502a2c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static class RSAParametersHelper | |
{ | |
public static RSAParameters FromPem(string pem) | |
{ | |
using var rsa = new RsaPem(); | |
rsa.ImportFromPem(pem); | |
return rsa.ExportParameters(); | |
} | |
class RsaPem : RSA | |
{ | |
private RSAParameters _rsaParameters; | |
public override RSAParameters ExportParameters(bool includePrivateParameters) => throw new NotImplementedException(); | |
public RSAParameters ExportParameters() | |
{ | |
return _rsaParameters; | |
} | |
public override void ImportParameters(RSAParameters parameters) | |
{ | |
_rsaParameters = new RSAParameters() | |
{ | |
D = parameters.D?.ToArray(), | |
DP = parameters.DP?.ToArray(), | |
DQ = parameters.DQ?.ToArray(), | |
Exponent = parameters.Exponent?.ToArray(), | |
InverseQ = parameters.InverseQ?.ToArray(), | |
Modulus = parameters.Modulus?.ToArray(), | |
P = parameters.P?.ToArray(), | |
Q = parameters.Q?.ToArray(), | |
}; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment