private static RSAParameters Convert(RSAParametersJson paramsJson) { return(new RSAParameters { Modulus = paramsJson.Modulus, Exponent = paramsJson.Exponent, P = paramsJson.P, Q = paramsJson.Q, DP = paramsJson.DP, DQ = paramsJson.DQ, InverseQ = paramsJson.InverseQ, D = paramsJson.D }); }
/// <summary> /// 获取RSA Key序列化Json /// </summary> /// <param name="rsa">RSA实例<see cref="RSA"/></param> /// <param name="includePrivateParameters">是否包含私钥</param> /// <returns></returns> internal static string ToJsonString(this RSA rsa, bool includePrivateParameters) { var 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)); }
public static string ToJsonString(this RSA rsa, bool includePrivateParameters) { RSAParameters parameters = rsa.ExportParameters(includePrivateParameters); var parasJson = new RSAParametersJson() { n = parameters.Modulus != null?Convert.ToBase64String(parameters.Modulus) : null, e = 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, qi = parameters.InverseQ != null?Convert.ToBase64String(parameters.InverseQ) : null, d = parameters.D != null?Convert.ToBase64String(parameters.D) : null }; return(JsonConvert.SerializeObject(parasJson)); }