bc-csharp icon indicating copy to clipboard operation
bc-csharp copied to clipboard

InvalidCastException when parsing a code sign p7b

Open acoder84 opened this issue 4 years ago • 1 comments

 var p7b = File.ReadAllBytes(path);
 var cmsSignedData = new Org.BouncyCastle.Cms.CmsSignedData(p7b);

System.InvalidCastException: Unable to cast object of type 'Org.BouncyCastle.Asn1.DerSequence' to type 'Org.BouncyCastle.Asn1.Asn1OctetString'. at Org.BouncyCastle.Cms.CmsSignedData..ctor(ContentInfo sigData) in /crypto/src/cms/CMSSignedData.cs:line 138 at Org.BouncyCastle.Cms.CmsSignedData..ctor(Byte[] sigBlock) in /crypto/src/cms/CMSSignedData.cs:line 62

https://github.com/bcgit/bc-csharp/blob/42f933608f60af7e9c36ffa3f9150b06b842a6ca/crypto/src/cms/CMSSignedData.cs#L138

Consider checking the type of signedData.EncapContentInfo.Content before casting.

File for test (rename to .p7b) BouncyCastle.Crypto.zip

acoder84 avatar Aug 02 '21 14:08 acoder84

This issue seems to be a duplicate of https://github.com/bcgit/bc-csharp/issues/232.

cristianst85 avatar Dec 22 '21 00:12 cristianst85