Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why rsaKey.PublicKey == rsaKey.PrivateKey #34

Closed
dev-ptdi opened this issue Mar 18, 2020 · 1 comment
Closed

Why rsaKey.PublicKey == rsaKey.PrivateKey #34

dev-ptdi opened this issue Mar 18, 2020 · 1 comment

Comments

@dev-ptdi
Copy link

Hi..

Why rsaKey.PublicKey == rsaKey.PrivateKey

var rsaKey = EncryptProvider.CreateRsaKey(RsaSize.R4096);

        string _publicKey = rsaKey.PublicKey;
        JObject _jo_public_key = JObject.Parse(_publicKey);
        string _public_key = (string)_jo_public_key["Modulus"];

        var _privateKey = rsaKey.PrivateKey;
        JObject _jo_private_key = JObject.Parse(_privateKey);
        string _private_key = (string)_jo_private_key["Modulus"];
@myloveCc
Copy link
Owner

The modulus same don't mean the privateKey equal publickKey.

  internal static string ToJsonString(this RSA rsa, bool includePrivateParameters)
        {
            RSAParameters parameters = rsa.ExportParameters(includePrivateParameters);

            var parasJson = new RSAParametersJson()
            {
                Modulus = parameters.Modulus != null ? Convert.ToBase64String(parameters.Modulus) : null,
                Exponent = parameters.Exponent != null ? Convert.ToBase64String(parameters.Exponent) : null,
                P = parameters.P != null ? Convert.ToBase64String(parameters.P) : null,
                Q = parameters.Q != null ? Convert.ToBase64String(parameters.Q) : null,
                DP = parameters.DP != null ? Convert.ToBase64String(parameters.DP) : null,
                DQ = parameters.DQ != null ? Convert.ToBase64String(parameters.DQ) : null,
                InverseQ = parameters.InverseQ != null ? Convert.ToBase64String(parameters.InverseQ) : null,
                D = parameters.D != null ? Convert.ToBase64String(parameters.D) : null
            };

            return JsonConvert.SerializeObject(parasJson);
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants