Another exception is EndOfStreamException:
{"DEF length 88 object truncated by 2"}
with the following stack trace:
   at Org.BouncyCastle.Asn1.DefiniteLengthInputStream.ToArray()
at Org.BouncyCastle.Asn1.Asn1InputStream.BuildObject(Int32 tag, Int32 tagNo, Int32 length)
   at Org.BouncyCastle.Asn1.Asn1InputStream.ReadObject()
   at Org.BouncyCastle.Asn1.Asn1Object.FromByteArray(Byte[] data)
at Org.BouncyCastle.Security.PublicKeyFactory.CreateKey(Byte[] keyInfoData) at TestConsole.PGP.xmlStringToPubKey(String xmlString) in PGP.cs:line 141
   at TestConsole.Test.Main(String[] args) in Test.cs:line 22
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()

On 2013-12-05 16:20, Bogdan Suvar wrote:
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