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:
### 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 be generated by the following command:
$> echo "USERNAME:PASSWURD" | base64
Im my blog post  Protect directory with username and password I show how to generate the password hash for Basic Auth via .htaccess file itself.
