Im kinda confused about the required/optional requirement for loading XML for a DSACryptoServiceProvider
.
From the this website, the following is the schema: Schema Definition:
<element name="DSAKeyValue" type="ds:DSAKeyValueType"/>
<complexType name="DSAKeyValueType">
<sequence>
<sequence minOccurs="0">
<element name="P" type="ds:CryptoBinary"/>
<element name="Q" type="ds:CryptoBinary"/>
</sequence>
<element name="G" type="ds:CryptoBinary" minOccurs="0"/>
<element name="Y" type="ds:CryptoBinary"/>
<element name="J" type="ds:CryptoBinary" minOccurs="0"/>
<sequence minOccurs="0">
<element name="Seed" type="ds:CryptoBinary"/>
<element name="PgenCounter" type="ds:CryptoBinary"/>
</sequence>
</sequence>
</complexType>
However, according to MSDN, the DsaKeyValue XML is defined as below:
<DSAKeyValue>
<!-- Child elements -->
P,
Q,
G?,
Y,
J?,
Seed,
PgenCounter
</DSAKeyValue>
Im getting a Bad data when importing from XML. Following is my code:
JsonDictionary privateKeyDictionary = (JsonDictionary) JsonReader.Parse(privateKey);
//FYI: this private signing key was generated using Keyczar.
var dsaParameterArray = privateKeyDictionary["publicKey"] as JsonDictionary;
DSACryptoServiceProvider signer = new DSACryptoServiceProvider(1024);
var pArray = Encoding.UTF8.GetBytes(dsaParameterArray["p"].ToString());
string p = Convert.ToBase64String(pArray);
var qArray = Encoding.UTF8.GetBytes(dsaParameterArray["q"].ToString());
string q = Convert.ToBase64String(qArray);
var gArray = Encoding.UTF8.GetBytes(dsaParameterArray["g"].ToString());
string g = Convert.ToBase64String(gArray);
var yArray = Encoding.UTF8.GetBytes(dsaParameterArray["y"].ToString());
string y = Convert.ToBase64String(yArray);
xml = String.Format("<DSAKeyValue><P>{0}</P><Q>{1}</Q><G>{2}</G><Y>{3}</Y><J/><Seed/><PgenCounter/></DSAKeyValue>", p, q, g, y);
doc = new XmlDocument();
doc.LoadXml(xml);
signer.FromXmlString(doc.InnerXml);
All that said, my problem is that I dont have "J", "Seed" and "PgenCounter" in my key hence I didnt supply them. According to the W3C, thats optional. However, I do have a "x" in my key but wasnt sure what that was.
According to the W3C the Seed and PgenCounter tags are optional. However, the MSDN defines it as required.
Ive tried removing the J, Seed and PgenCounter tags and that didnt seem to help.
Thanks!