for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/*
* This file is part of the DUKPT package.
*
* Copyright (c) 2016-2017 Tonic Health <[email protected]>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace TonicForHealth\DUKPT\Key;
/**
* Class AbstractKey
* @author Vitalii Ekert <[email protected]>
abstract class AbstractKey implements KeyInterface
{
* The key as a binary data string
* @var string
private $binKey;
* AbstractKey constructor.
* @param string $binKey The key as a binary data string
* @throws \InvalidArgumentException If the provided key has a wrong size
public function __construct($binKey)
$this->binKey = $this->validateKey($binKey);
}
* {@inheritdoc}
public function toBinary()
return $this->binKey;
public function toHexadecimal()
return strtoupper(bin2hex($this->toBinary()));
public function __toString()
return $this->toHexadecimal();
* Validate the specified key
* @param string $binKey The specified key as a binary data string
* @return string Returns the validated key as a binary data string
abstract protected function validateKey($binKey);