Hi,
I'm currently trying to create an AsymmetricKeyParameter public key parameter from an xml string like this:

public static AsymmetricKeyParameter xmlStringToPubKey(string xmlString)
        {
            //AsymmetricCipherKeyPair keyPair;
            if (String.IsNullOrEmpty(xmlString))
            {
                Console.WriteLine("Empty XML string received");
                return null;
            }
            else
            {
                XDocument xdoc = XDocument.Parse(xmlString);
return PublicKeyFactory.CreateKey(Streamify(xdoc.Descendants("Modulus").First().Value));
            }
        }

However, I'm getting an exception when calling CreateKey on PublicKeyFactory obj. xdoc.Descendants returns a string which needs to be converted into an array of bytes. I've tried different ways to convert the string:
- Encoding.Unicode.getBytes(xmlString)
- getBytes(xmlString) method I've created to return a byte array from a string
- Streamify - another method I've created to return a Stream

While I get different exceptions on each of the above methods none seem to work. Any hints appreciated.

Reply via email to