ASN1 out of memory. during a signedCMS.decode
- by JL
I am having a problem using the signedCMS.decode routine. See the code below.
The error seems to occur when the file size is too big in this case 11MB.
private static void RemoveZfoSignature(string zfoFileName)
{
byte[] fileContents = File.ReadAllBytes(zfoFileName);
var contentInfo = new ContentInfo(fileContents);
var signedCms = new SignedCms(contentInfo);
// This line throws the error 100% of the time
signedCms.Decode(fileContents);
signedCms.RemoveSignature(0);
byte[] outfile = signedCms.ContentInfo.Content;
string outFileName = zfoFileName.Replace(".zfo", "_tmp.zfo");
File.WriteAllBytes(outFileName, outfile);
}
Here is the exact error:
"System.Security.Cryptography.CryptographicException: ASN1 out of memory.
at System.Security.Cryptography.Pkcs.SignedCms.OpenToDecode(Byte[] encodedMessage, ContentInfo contentInfo, Boolean detached)
at System.Security.Cryptography.Pkcs.SignedCms.Decode(Byte[] encodedMessage)
at ConsoleApplication2.Program.RemoveZfoSignature(String zfoFileName) in C:\\Users\\\\Documents\\Visual Studio 2008\\Projects\\ConsoleApplication2\\ConsoleApplication2\\Program.cs:line 30"
Any idea on how to fix this?