This is a difficult question to answer, not knowing how the X509Certificate is encoded, but provided that you have the material to encode, you can do something like the following:
var document = new XmlDocument(); document.LoadXml(txtXml.Text); var cert = document.SelectSingleNode("X509Data/X509Certificate").InnerText; var x509 = new X509Certificate2(data);
Then you can write the file to disk using the standard file I / O logic.
source share