Help with my first custom cleaner

25 views
Skip to first unread message

Jason Pratt

unread,
Mar 2, 2024, 9:32:39 AMMar 2
to TextSoap
Hi everyone, I just started using TextSoap 9.  In my work, I'm constantly coming across base64 encoded certificates.  The text looks like this:

MIICEjCCAXsCAg36MA0GCSqGSIb3DQEBBQUAMIGbMQswCQYDVQQGEwJKUDEOMAwGA1UECBMFVG9reW8xEDAOBgNVBAcTB0NodW8ta3UxETAPBgNVBAoTCEZyYW5rNEREMRgwFgYDVQQLEw9XZWJDZXJ0IFN1cHBvcnQxGDAWBgNVBAMTD0ZyYW5rNEREIFdlYiBDQTEjMCEGCSqGSIb3DQEJARYUc3VwcG9ydEBmcmFuazRkZC5jb20wHhcNMTIwODIyMDUyNjU0WhcNMTcwODIxMDUyNjU0WjBKMQswCQYDVQQGEwJKUDEOMAwGA1UECAwFVG9reW8xETAPBgNVBAoMCEZyYW5rNEREMRgwFgYDVQQDDA93d3cuZXhhbXBsZS5jb20wXDANBgkqhkiG9w0BAQEFAANLADBIAkEAm/xmkHmEQrurE/0re/jeFRLl8ZPjBop7uLHhnia7lQG/5zDtZIUC3RVpqDSwBuw/NTweGyuP+o8AG98HxqxTBwIDAQABMA0GCSqGSIb3DQEBBQUAA4GBABS2TLuBeTPmcaTaUW/LCB2NYOy8GMdzR1mx8iBIu2H6/E2tiY3RIevV2OW61qY2/XRQg7YPxx3ffeUugX9F4J/iPnnu1zAxxyBy2VguKv4SWjRFoRkIfIlHX0qVviMhSlNy2ioFLy7JcPZb+v3ftDGywUqcBiVDoea0Hn+GmxZA

It's just one long line of characters.  I want to take text like that and convert it to this:

-----BEGIN CERTIFICATE-----

MIICEjCCAXsCAg36MA0GCSqGSIb3DQEBBQUAMIGbMQswCQYDVQQGEwJKUDEOMAwG

A1UECBMFVG9reW8xEDAOBgNVBAcTB0NodW8ta3UxETAPBgNVBAoTCEZyYW5rNERE

MRgwFgYDVQQLEw9XZWJDZXJ0IFN1cHBvcnQxGDAWBgNVBAMTD0ZyYW5rNEREIFdl

YiBDQTEjMCEGCSqGSIb3DQEJARYUc3VwcG9ydEBmcmFuazRkZC5jb20wHhcNMTIw

ODIyMDUyNjU0WhcNMTcwODIxMDUyNjU0WjBKMQswCQYDVQQGEwJKUDEOMAwGA1UE

CAwFVG9reW8xETAPBgNVBAoMCEZyYW5rNEREMRgwFgYDVQQDDA93d3cuZXhhbXBs

ZS5jb20wXDANBgkqhkiG9w0BAQEFAANLADBIAkEAm/xmkHmEQrurE/0re/jeFRLl

8ZPjBop7uLHhnia7lQG/5zDtZIUC3RVpqDSwBuw/NTweGyuP+o8AG98HxqxTBwID

AQABMA0GCSqGSIb3DQEBBQUAA4GBABS2TLuBeTPmcaTaUW/LCB2NYOy8GMdzR1mx

8iBIu2H6/E2tiY3RIevV2OW61qY2/XRQg7YPxx3ffeUugX9F4J/iPnnu1zAxxyBy

2VguKv4SWjRFoRkIfIlHX0qVviMhSlNy2ioFLy7JcPZb+v3ftDGywUqcBiVDoea0

Hn+GmxZA

-----END CERTIFICATE-----


Basically inserting "-----BEGIN CERTIFICATE-----" at the top, "-----END CERTIFICATE-----" at the bottom, and inserting a line break after 64 characters.


In my Custom Cleaner, I tried using the "Custom Text Wrap" option, but it doesn't seem to do anything.  Can anyone tell me the best way to accomplish this task, please?


Thank you!

Mark Munz

unread,
Mar 19, 2024, 2:25:09 PMMar 19
to text...@googlegroups.com
Apologies for the delayed response.

"Custom Text Wrap" tries to do word wrapping as part of its action, so it will fail because there are no word breaks. Probably should be stated more explicitly.
However, you can accomplish this task with the ever-resourceful Regular Expression. Here is the solution:

image.png

The regex basically takes 64 characters, inserts a return and then repeats for the rest of the text.
The Insert Text actions will then put the BEGIN/END CERTIFICATE text before/after the base64 encoded text


--
You received this message because you are subscribed to the Google Groups "TextSoap" group.
To unsubscribe from this group and stop receiving emails from it, send an email to textsoap+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/textsoap/c41b45c3-7851-4141-9f5d-3906b586002en%40googlegroups.com.


--
Mark Munz
unmarked software
https://textsoap.com/

Jason Pratt

unread,
Mar 21, 2024, 12:56:30 AMMar 21
to TextSoap
Thank you so much Mark! This worked great and it was a good practical example of how to make custom cleaners.  Much appreciated :)
Reply all
Reply to author
Forward
0 new messages