Skip to content

Instantly share code, notes, and snippets.

@esskar
Last active August 29, 2015 14:03
Show Gist options
  • Save esskar/6115b2f73b01372d38e5 to your computer and use it in GitHub Desktop.
Save esskar/6115b2f73b01372d38e5 to your computer and use it in GitHub Desktop.
CMS Enveloped Data Dumper.
using System;
using System.IO;
using System.Security.Cryptography.Pkcs;
using System.Security.Cryptography.Xml;
namespace CmsDumper
{
class Program
{
static void Main(string[] args)
{
var cms = new EnvelopedCms();
cms.Decode(File.ReadAllBytes(args[0]));
Console.WriteLine("CMS Version: {0}", cms.Version);
Console.WriteLine("CMS ContentType: {0}", cms.ContentInfo.ContentType.FriendlyName);
Console.WriteLine("CMS ContentEncryptionAlgorithm: {0}", cms.ContentEncryptionAlgorithm.Oid.FriendlyName);
Console.WriteLine("CMS RecipientInfos: {0}", cms.RecipientInfos.Count);
foreach (var recipient in cms.RecipientInfos)
{
if (recipient.RecipientIdentifier.Type == SubjectIdentifierType.IssuerAndSerialNumber)
{
var rid = (X509IssuerSerial) recipient.RecipientIdentifier.Value;
Console.WriteLine("\tCMS Recipient:");
Console.WriteLine("\t\tIssuer: {0}", rid.IssuerName);
Console.WriteLine("\t\tSerial: {0}", rid.SerialNumber);
}
else
{
Console.WriteLine("\tCMS Recipient: {0}", recipient.RecipientIdentifier.Value);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment