for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* Class CryptoAbstract
*
* @filesource CryptoAbstract.php
* @created 02.04.2016
* @package chillerlan\Threema\Crypto
* @author Smiley <[email protected]>
* @copyright 2016 Smiley
* @license MIT
*/
namespace chillerlan\Threema\Crypto;
abstract class CryptoAbstract implements CryptoInterface{
* @inheritdoc
public function bin2hex(string $bin):string{
return bin2hex($bin);
}
public function hex2bin(string $hex):string{
return hex2bin($hex);
public function getRandomBytes(int $length):string{
return random_bytes($length);
public function hmac_hash(string $str, string $hmacKey):string{
return hash_hmac('sha256', $str, $hmacKey);
public function getPadBytes():string {
$padbytes = 0;
while($padbytes < 1 || $padbytes > 255){
$padbytes = ord($this->getRandomBytes(1));
return str_repeat(chr($padbytes), $padbytes);