EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Content extraction from p7m

Also by EldoS: CallbackDisk
Create virtual disks backed by memory or custom location, expose disk images as disks and more.
Posted: 05/17/2011 06:01:11
by Christoph Moar (Premium support level)
Joined: 08/28/2009
Posts: 46

I'm currently trying to extract the content document from a p7m file using the following recipe, which I 've found on another thread of this forum:

To break existing p7m message into a document and a signature, please do the following:
1) Load the message into the TElSignedCMSMessage object (using the Open method),
2) Set TElSignedCMSMessage.Detached property to true,
3) Call TElSignedCMSMessage.Save() to save the message with excluded document (p7s),
4) Read the body of the document using TElSignedCMSMessage.Content.Read() method.

I'm not quite sure about a couple of points though:
The open() method asks for 2 streams, while I have just 1 (the file stream).
Is the save() method required in order to access the content data?

No matter what I try, I am unable to read data from the Content attribute.

Thank you for your help.
Posted: 05/17/2011 06:18:48
by Vsevolod Ievgiienko (EldoS Corp.)

Thank you for contacting us.

The procedure of data extraction is shorter. Here is a sample code:
  CMS : TElSignedCMSMessage;
  S : TFileStream;
  Res : ByteArray;
  S := TFileStream.Create('file.p7m', fmOpenReadWrite);

  CMS := TElSignedCMSMessage.Create(nil);
  CMS.Open(S, nil);

  SetLength(Res, CMS.Content.Size);
  CMS.Content.Read(@Res[0], CMS.Content.Size, 0);

  // now Res contains the document
Posted: 05/17/2011 07:32:48
by Christoph Moar (Premium support level)
Joined: 08/28/2009
Posts: 46

Thank you, now it works!



Topic viewed 1188 times

Number of guests: 1, registered members: 0, in total hidden: 0


Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!