EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Return ds:object encoded in base-64 format

Also by EldoS: Callback File System
Create virtual file systems and disks, expose and manage remote data as if they were files on the local disk.
#37106
Posted: 06/24/2016 15:04:57
by Jacek Badziak (Premium support level)
Joined: 06/03/2016
Posts: 2

Dear Team,

I'm using XMLBlackBox to sign XML files according to the xades standard. The receipient requires that the ds:object (the actual signed message) will be sent encoded with base-64 algorithm. Currently I'm using the DOM methods to encode the document then place it in the TELXMLDoucment along with its signature and it actually works ! Document is properly validated by all major authorities in PL. However - I'm sure that there is a better way of doing that (without usage of all these dom methods and manual encoding of the node and its children into the BASE-64). Would You be kind enough to navigate to a right method ? Speaking other words - is there any option to convert the entire signed xml document to base-64 on the fly ?

Kind regards,

Jacek
#37107
Posted: 06/24/2016 15:13:48
by Eugene Mayevski (EldoS Corp.)

In your case the original document is treated as an opaque object being signed. There's no built-in way to perform encoding automatically by XMLDSig components.
If you are using .NET DOM, it can make sense to use TElXMLDOMDocument and SecureBlackbox's base64 encoding methods instead, but otherwise I can offer no optimizations.

BTW should you convert nodes one by one, or the complete XML as one piece of data?


Sincerely yours
Eugene Mayevski
#37108
Posted: 06/24/2016 15:21:51
by Jacek Badziak (Premium support level)
Joined: 06/03/2016
Posts: 2

Hi,

This is the piece of code that I'm using the create my base-64 object
Code
Dim fmldocument As New TElXMLDOMDocument
(...)

        b64 = (Encoding.UTF8.GetBytes(fmldocument.FirstChild.GetOuterXMLCanonical(SBXMLDefs.Unit.xcmCanon)))
z = Convert.ToBase64String(b64, Base64FormattingOptions.None)
        ob.ID = "Doc-" + srand
        ob.Encoding = "http://www.w3.org/2000/09/xmldsig#base64"
        ob.DataList.Add(fmldocument.CreateTextNode(z))
        signer.Signature.Objects.Add(ob)


As I said - this actually works but the code doesn't seem optimized and I'm looking for a better way of doing that. I bought the XMLBlackBox and You have mentioned that there are built-in methods of doing the base64 encoding. So how to do that ?

Regards,

Jacek
#37109
Posted: 06/24/2016 15:36:03
by Eugene Mayevski (EldoS Corp.)

Base64 encoding can be done with a call to SBEncoding.Unit.Base64EncodeArray() or SBEncoding.Unit.Base64EncodeString() method depending on what you have as input. One optimization in your case could be to skip UTF8 step *if* this format (UTF16 by default) is accepted. If it is, then the code would look like

Code
z = SBEncoding.Unit.Base64EncodeString(fmldocument.FirstChild.GetOuterXMLCanonical(SBXMLDefs.Unit.xcmCanon), false);


This would work a tiny bit faster, as we skip the UTF8 conversion.

On a side note it would help a lot if you used CODE button located above the text entry box (alternatively you can write [ CODE ] and [ /CODE ] tags by hand) to mark the beginning and the end of the code blocks in your messages. This would enable syntax highlighting and line numbering on the code and make it easier for analysis.


Sincerely yours
Eugene Mayevski
#37110
Posted: 06/24/2016 15:53:13
by Dmytro Bogatskyy (EldoS Corp.)

Hi,

Quote
b64 = (Encoding.UTF8.GetBytes(fmldocument.FirstChild.GetOuterXMLCanonical(SBXMLDefs.Unit.xcmCanon)))

In the first line, you should use DocumentElement property, but not FirstChild.
Also, you can save a document into MemoryStream and then use MemoryStream.ToArray() method to get the same value as in b64 (while saving the document you may need to write it without BOM, byte-order-mark).
Quote
z = Convert.ToBase64String(b64, Base64FormattingOptions.None)
and You have mentioned that there are built-in methods of doing the base64 encoding.

Yes, for example you can use ConvertToBase64String function:
Code
z = SBXMLUtils.Unit.ConvertToBase64String(b64)

Or, if you need to tune up Base64 encoding, you can use SBEncoding.Unit.Base64Encode() function.
Also by EldoS: CallbackDisk
Create virtual disks backed by memory or custom location, expose disk images as disks and more.

Reply

Statistics

Topic viewed 1040 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!