diff --git a/src/Algorithm.php b/src/Algorithm.php index b35d768..a4825af 100644 --- a/src/Algorithm.php +++ b/src/Algorithm.php @@ -14,15 +14,18 @@ abstract class Algorithm public static function create($name) { switch ($name) { - case 'hmac-sha1': - return new HmacAlgorithm('sha1'); - break; - case 'hmac-sha256': - return new HmacAlgorithm('sha256'); - break; - default: - throw new Exception("No algorithm named '$name'"); - break; + case 'hmac-sha1': + return new HmacAlgorithm('sha1'); + break; + case 'hmac-sha256': + return new HmacAlgorithm('sha256'); + break; + case 'rsa-sha512': + return new RsaAlgorithm('sha512'); + break; + default: + throw new Exception("No algorithm named '$name'"); + break; } } } diff --git a/src/RsaAlgorithm.php b/src/RsaAlgorithm.php new file mode 100644 index 0000000..dcd575e --- /dev/null +++ b/src/RsaAlgorithm.php @@ -0,0 +1,38 @@ +digestName = $digestName; + } + + /** + * @return string + */ + public function name() + { + return sprintf('rsa-%s', $this->digestName); + } + + /** + * @param string $key + * @param string $data + * + * @return string + */ + public function sign($privateKey, $data) + { + openssl_sign($data, $signature, $privateKey, 'RSA-SHA512'); + + return $signature; + } +}