for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
/*
* This file is part of the LetsEncrypt ACME client.
*
* @author Ivanov Aleksandr <[email protected]>
* @copyright 2019-2020
* @license https://github.com/misantron/letsencrypt-client/blob/master/LICENSE MIT License
*/
namespace LetsEncrypt\Helper;
final class Base64SafeEncoder
{
public function encode(string $input): string
return str_replace('=', '', strtr(base64_encode($input), '+/', '-_'));
}
public function decode(string $input): string
$remainder = strlen($input) % 4;
if ($remainder) {
$input .= str_repeat('=', 4 - $remainder);
return base64_decode(strtr($input, '-_', '+/'));
public function hashEncode(string $payload): string
return $this->encode(hash('sha256', $payload, true));