Base64 encode on shell
Sometimes you need to encode a string with a base64 encoding. For example when trying to send a HTTP request with a Basic Authentication header like that:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
### own controller: POST http://thedomain.com/webhook/post?XDEBUG_SESSION_START=11931 Content-Type: application/json Authorization: Basic c25zOlVzZVRoZWZvcmNlCg== { "uuid": "08e9a8d3-9279-4af5-88ff-ebe42359f0e0", "eventname": "peng.page.publish", "data": { "sitemap_id": "1234", "locale": "de_DE", "path": "unigue/page/path", "title": "Testpage over API", "meta_title": "string", "meta_keywords": "string", "meta_description": "string", "content": "<p >This is a nice dummy storypage with widget marker.</p><p>{{widget type=\"Magento\\Catalog\\Block\\Product\\Widget\\Link\" anchor_text=\"TESTPRODUKT\" title=\"TESTPRODUKT\" template=\"product/widget/link/link_inline.phtml\" id_path=\"product/1\"}}</p>", "active": true, "css": "", "js": "" } } ### |
As you can see the Basic Auth username and password are included in the request as a base64 encoded string. On the Linux shell this string can […]