Beispiel #1
0
        /// <summary>
        /// Sbusta un file timestampato, estraendo l'eventuale file firmato (pkcs) o il payload nel caso non fosse firmato.
        /// </summary>
        /// <param name="fileContents">bytearray del file tsd o m7m</param>
        /// <returns></returns>
        public static byte[] sbustaFileTimstamped(byte[] fileContents)
        {
            TsType tipo = getFileType(fileContents);

            if (tipo == TsType.TSD)
            {
                PKCS_Utils.tsd tsd = new PKCS_Utils.tsd();
                tsd.explode(fileContents);
                fileContents = tsd.Data.Content;
            }

            if (tipo == TsType.M7M)
            {
                PKCS_Utils.m7m m7m = new PKCS_Utils.m7m();
                m7m.explode(fileContents);
                fileContents = m7m.Data.Content;
            }
            return(fileContents);
        }
Beispiel #2
0
        /// <summary>
        /// Sbusta un file timstamped e firmato, fino arrivare al file originale (payload)
        /// </summary>
        /// <param name="fileContents"></param>
        /// <returns>bytearray del file tsd, m7m, o p7m</returns>
        public static byte[] sbustaFileFirmato(byte[] fileContents)
        {
            //controlla se è base64
            String strfileContents = System.Text.ASCIIEncoding.ASCII.GetString(fileContents);

            if (IsBase64Encoded(strfileContents))
            {
                fileContents = Convert.FromBase64String(strfileContents);
            }

            TsType tipo = getFileType(fileContents);

            if (tipo == TsType.PKCS)
            {
                CmsSignedData cms = new CmsSignedData(fileContents);
                fileContents = (byte[])cms.SignedContent.GetContent();
            }

            if (tipo == TsType.TSD)
            {
                PKCS_Utils.tsd tsd = new PKCS_Utils.tsd();
                tsd.explode(fileContents);
                fileContents = tsd.Data.Content;
            }

            if (tipo == TsType.M7M)
            {
                PKCS_Utils.m7m m7m = new PKCS_Utils.m7m();
                m7m.explode(fileContents);
                fileContents = m7m.Data.Content;
            }

            //non conosco il tipo, esco
            if (tipo == TsType.UNKNOWN)
            {
                return(fileContents);
            }


            //ricorsione per arrivare al singolo documento
            return(sbustaFileFirmato(fileContents));
        }