[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 declare(strict_types=1); 4 5 /* 6 * The MIT License (MIT) 7 * 8 * Copyright (c) 2014-2019 Spomky-Labs 9 * 10 * This software may be modified and distributed under the terms 11 * of the MIT license. See the LICENSE file for details. 12 */ 13 14 namespace Cose\Algorithm\Signature\RSA; 15 16 use Assert\Assertion; 17 use Cose\Algorithm\Signature\Signature; 18 use Cose\Key\Key; 19 use Cose\Key\RsaKey; 20 21 abstract class RSA implements Signature 22 { 23 public function sign(string $data, Key $key): string 24 { 25 $key = $this->handleKey($key); 26 Assertion::true($key->isPrivate(), 'The key is not private'); 27 28 $result = openssl_sign($data, $signature, $key->asPem(), $this->getHashAlgorithm()); 29 Assertion::true($result, 'Unable to sign the data'); 30 31 return $signature; 32 } 33 34 public function verify(string $data, Key $key, string $signature): bool 35 { 36 $key = $this->handleKey($key); 37 38 return 1 === openssl_verify($data, $signature, $key->asPem(), $this->getHashAlgorithm()); 39 } 40 41 private function handleKey(Key $key): RsaKey 42 { 43 return new RsaKey($key->getData()); 44 } 45 46 abstract protected function getHashAlgorithm(): int; 47 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |