public override void FromXmlString(string xmlString) { if (xmlString == null) { throw new ArgumentNullException("xmlString"); } DSAParameters parameters = new DSAParameters(); SecurityElement topElement = new Parser(xmlString).GetTopElement(); string inputBuffer = topElement.SearchForTextOfLocalName("P"); if (inputBuffer == null) { throw new CryptographicException(Environment.GetResourceString("Cryptography_InvalidFromXmlString", new object[] { "DSA", "P" })); } parameters.P = Convert.FromBase64String(Utils.DiscardWhiteSpaces(inputBuffer)); string str2 = topElement.SearchForTextOfLocalName("Q"); if (str2 == null) { throw new CryptographicException(Environment.GetResourceString("Cryptography_InvalidFromXmlString", new object[] { "DSA", "Q" })); } parameters.Q = Convert.FromBase64String(Utils.DiscardWhiteSpaces(str2)); string str3 = topElement.SearchForTextOfLocalName("G"); if (str3 == null) { throw new CryptographicException(Environment.GetResourceString("Cryptography_InvalidFromXmlString", new object[] { "DSA", "G" })); } parameters.G = Convert.FromBase64String(Utils.DiscardWhiteSpaces(str3)); string str4 = topElement.SearchForTextOfLocalName("Y"); if (str4 == null) { throw new CryptographicException(Environment.GetResourceString("Cryptography_InvalidFromXmlString", new object[] { "DSA", "Y" })); } parameters.Y = Convert.FromBase64String(Utils.DiscardWhiteSpaces(str4)); string str5 = topElement.SearchForTextOfLocalName("J"); if (str5 != null) { parameters.J = Convert.FromBase64String(Utils.DiscardWhiteSpaces(str5)); } string str6 = topElement.SearchForTextOfLocalName("X"); if (str6 != null) { parameters.X = Convert.FromBase64String(Utils.DiscardWhiteSpaces(str6)); } string str7 = topElement.SearchForTextOfLocalName("Seed"); string str8 = topElement.SearchForTextOfLocalName("PgenCounter"); if ((str7 != null) && (str8 != null)) { parameters.Seed = Convert.FromBase64String(Utils.DiscardWhiteSpaces(str7)); parameters.Counter = Utils.ConvertByteArrayToInt(Convert.FromBase64String(Utils.DiscardWhiteSpaces(str8))); } else if ((str7 != null) || (str8 != null)) { if (str7 == null) { throw new CryptographicException(Environment.GetResourceString("Cryptography_InvalidFromXmlString", new object[] { "DSA", "Seed" })); } throw new CryptographicException(Environment.GetResourceString("Cryptography_InvalidFromXmlString", new object[] { "DSA", "PgenCounter" })); } this.ImportParameters(parameters); }
public override void FromXmlString(string xmlString) { if (xmlString == null) { throw new ArgumentNullException("xmlString"); } RSAParameters parameters = new RSAParameters(); SecurityElement topElement = new Parser(xmlString).GetTopElement(); string inputBuffer = topElement.SearchForTextOfLocalName("Modulus"); if (inputBuffer == null) { throw new CryptographicException(Environment.GetResourceString("Cryptography_InvalidFromXmlString", new object[] { "RSA", "Modulus" })); } parameters.Modulus = Convert.FromBase64String(Utils.DiscardWhiteSpaces(inputBuffer)); string str2 = topElement.SearchForTextOfLocalName("Exponent"); if (str2 == null) { throw new CryptographicException(Environment.GetResourceString("Cryptography_InvalidFromXmlString", new object[] { "RSA", "Exponent" })); } parameters.Exponent = Convert.FromBase64String(Utils.DiscardWhiteSpaces(str2)); string str3 = topElement.SearchForTextOfLocalName("P"); if (str3 != null) { parameters.P = Convert.FromBase64String(Utils.DiscardWhiteSpaces(str3)); } string str4 = topElement.SearchForTextOfLocalName("Q"); if (str4 != null) { parameters.Q = Convert.FromBase64String(Utils.DiscardWhiteSpaces(str4)); } string str5 = topElement.SearchForTextOfLocalName("DP"); if (str5 != null) { parameters.DP = Convert.FromBase64String(Utils.DiscardWhiteSpaces(str5)); } string str6 = topElement.SearchForTextOfLocalName("DQ"); if (str6 != null) { parameters.DQ = Convert.FromBase64String(Utils.DiscardWhiteSpaces(str6)); } string str7 = topElement.SearchForTextOfLocalName("InverseQ"); if (str7 != null) { parameters.InverseQ = Convert.FromBase64String(Utils.DiscardWhiteSpaces(str7)); } string str8 = topElement.SearchForTextOfLocalName("D"); if (str8 != null) { parameters.D = Convert.FromBase64String(Utils.DiscardWhiteSpaces(str8)); } this.ImportParameters(parameters); }