Ah okay, I'm pretty sure I was completely wrong with my original assessment. It's a bug.
Can you replace the head of the foreach with the following? Asn1Sequence seq = DerSequence.GetInstance(FromExtensionValue(extVal)); foreach (Asn1Encodable primName in seq) { IList list = Platform.CreateArrayList(); GeneralName genName = GeneralName.GetInstance(primName); That will do the trick, Regards, David On 28/12/16 21:19, Eduardo Marques wrote: > > I'm using the project bccrypto-csharp-1.8.1, > > > The error is in X509ExtensionUtilities at line 47: > > > foreach (GeneralName genName in seq) > > > Att. > > ------------------------------------------------------------------------ > *De:* Eduardo Marques <eduardo_marqu...@hotmail.com> > *Enviado:* quarta-feira, 28 de dezembro de 2016 07:59:46 > *Para:* dev-crypto-csharp@bouncycastle.org; d...@autochthonous.org > *Assunto:* Re: [dev-crypto-csharp] Error using GetSubjectAlternativeNames > > > in > Org.BouncyCastle.X509.Extension.X509ExtensionUtilities.GetAlternativeName(Asn1OctetString > extVal) > at C:\BouncyCastle\crypto\src\x509\extension\X509ExtensionUtil.cs:linha 82 > em WindowsApplication1.Form1.Button1_Click(Object sender, EventArgs > e) na c:\users\eduardo\documents\visual studio > 2015\Projects\WindowsApplication1\WindowsApplication1\Form1.vb:linha 37 > in System.Windows.Forms.Control.OnClick(EventArgs e) > in System.Windows.Forms.Button.OnClick(EventArgs e) > in System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) > in System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons > button, Int32 clicks) > in System.Windows.Forms.Control.WndProc(Message& m) > in System.Windows.Forms.ButtonBase.WndProc(Message& m) > in System.Windows.Forms.Button.WndProc(Message& m) > in System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr > hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) > in System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) > > in > System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr > dwComponentID, Int32 reason, Int32 pvLoopData) > > in System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 > reason, ApplicationContext context) > > in System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 > reason, ApplicationContext context) > > in > Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun() > > in > Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel() > > in > Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] > commandLine) > in WindowsApplication1.My.MyApplication.Main(String[] Args) na > :linha 81 > in System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, > String[] args) > in System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence > assemblySecurity, String[] args) > in Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() > in System.Threading.ExecutionContext.RunInternal(ExecutionContext > executionContext, ContextCallback callback, Object state, Boolean > preserveSyncCtx) > in System.Threading.ExecutionContext.Run(ExecutionContext > executionContext, ContextCallback callback, Object state, Boolean > preserveSyncCtx) > in System.Threading.ExecutionContext.Run(ExecutionContext > executionContext, ContextCallback callback, Object state) > in System.Threading.ThreadHelper.ThreadStart() > > I'm using version 1.8. > > > Att. > > ------------------------------------------------------------------------ > *De:* David Hook <d...@autochthonous.org> > *Enviado:* terça-feira, 27 de dezembro de 2016 20:40:29 > *Para:* eduardo_marqu...@hotmail.com; dev-crypto-csharp@bouncycastle.org > *Assunto:* Re: [dev-crypto-csharp] Error using GetSubjectAlternativeNames > > > What version are you using? Looking at the code for the current one > it's not clear that this exception is possible. Is there a stack trace > associated with the exception? > > Regards, > > David > > On 28/12/16 07:06, Eduardo Marques wrote: >> Good Afternoon, >> >> I'm trying to use your solution to take some information from the >> certificate. >> >> When i try to use GetSubjectAlternativeNames it's is giving me error >> and i don't know what else i can do. >> >> The error is "it is not possible to convert an object of >> type 'Org.BouncyCastle.Asn1.DerTaggedObject' >> to Org.BouncyCastle.Asn1.X509.GeneralName". >> >> The code below: >> >> 'ox509 is my certificate from X509Certificate2 >> >> Dim certificate As Org.BouncyCastle.X509.X509Certificate >> Dim func As New Org.BouncyCastle.X509.X509CertificateParser >> certificate = func.ReadCertificate(oX509Cert.RawData) >> >> Dim identities As IList(Of String) = New List(Of String)() >> Dim alternativeNames As Collection = >> X509ExtensionUtilities.GetSubjectAlternativeNames(certificate) >> >> Someone can help me? >> >> Att. >> >