# Estrazione xml da file p7m

**URL:** <https://forum.italia.it/t/estrazione-xml-da-file-p7m/8032>\
**Category:** Fatturazione Elettronica\
**Created:** [11 Febbraio 2019, 4:18pm UTC](https://forum.italia.it/t/estrazione-xml-da-file-p7m/8032 "2019-02-11T16:18:14Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![vbato](https://forum.italia.it/letter_avatar_proxy/v4/letter/v/3e96dc/32.png) [@vbato](https://forum.italia.it/u/vbato)\
**Post date:** [11 Febbraio 2019, 4:50pm UTC](https://forum.italia.it/t/estrazione-xml-da-file-p7m/8032/4 "2019-02-11T16:50:52Z")

</div>

Ho visto nell’altro thread che usi C#. Puoi fare tutto in .NET senza altre librerie. Per estrarre il contenuto del .p7m (dopo aver decodificato l’eventuale base64) puoi usare la seguente funzione:

```
    private byte[] EstraiFileDaP7M(byte[] signedData)
    {
        SignedCms cms = new SignedCms();
        cms.Decode(signedData);

        if (cms.Detached) {
            throw new InvalidOperationException("Cannot extract enveloped content from a detached signature.");
        }

        return cms.ContentInfo.Content;
    }

```

La classe `SignedCms` sta in `System.Security.Cryptography.Pkcs`.

---

_[View the full topic](https://forum.italia.it/t/estrazione-xml-da-file-p7m/8032)._
