[ 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\ECDSA; 15 16 use Assert\Assertion; 17 use Cose\Algorithm\Signature\Signature; 18 use Cose\Key\Ec2Key; 19 use Cose\Key\Key; 20 21 abstract class ECDSA implements Signature 22 { 23 public function __construct() 24 { 25 if (!method_exists($this, 'getSignaturePartLength')) { 26 @trigger_error('The method "getSignaturePartLength" is needed since 2.1 and will be mandatory in v3.0', E_USER_DEPRECATED); 27 } 28 } 29 30 public function sign(string $data, Key $key): string 31 { 32 $key = $this->handleKey($key); 33 $result = openssl_sign($data, $signature, $key->asPEM(), $this->getHashAlgorithm()); 34 Assertion::true($result, 'Unable to sign the data'); 35 36 return $signature; 37 } 38 39 public function verify(string $data, Key $key, string $signature): bool 40 { 41 $key = $this->handleKey($key); 42 $publicKey = $key->toPublic(); 43 44 return 1 === openssl_verify($data, $signature, $publicKey->asPEM(), $this->getHashAlgorithm()); 45 } 46 47 private function handleKey(Key $key): Ec2Key 48 { 49 $key = new Ec2Key($key->getData()); 50 Assertion::eq($key->curve(), $this->getCurve(), 'This key cannot be used with this algorithm'); 51 52 return $key; 53 } 54 55 abstract protected function getCurve(): int; 56 57 abstract protected function getHashAlgorithm(): int; 58 }
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 |