From 31c0f141cc33170bd6044e8c2fc0c1f7d471ac0f Mon Sep 17 00:00:00 2001 From: Mark Ogilvie Date: Fri, 28 May 2021 14:51:24 +0100 Subject: [PATCH 1/2] Add RSA algorithm --- src/Algorithm.php | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) 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; } } } From e4c263d3937fc47ccda00f4c7212302be1636f22 Mon Sep 17 00:00:00 2001 From: Mark Ogilvie Date: Fri, 28 May 2021 14:52:56 +0100 Subject: [PATCH 2/2] Create RsaAlgorithm.php --- src/RsaAlgorithm.php | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/RsaAlgorithm.php 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; + } +}