PHP Classes

File: src/CryptographyKeys/SigningSecretKey.php

Recommend this page to a friend!
  Packages of Scott Arciszewski   sapient   src/CryptographyKeys/SigningSecretKey.php   Download  
File: src/CryptographyKeys/SigningSecretKey.php
Role: Class source
Content type: text/plain
Description: Class source
Class: sapient
Add a security layer to server to server requests
Author: By
Last change: Capitalization.
Date: 9 years ago
Size: 1,154 bytes
 

Contents

Class file image Download
<?php
declare(strict_types=1);
namespace ParagonIE\Sapient\CryptographyKeys;

use ParagonIE\Sapient\CryptographyKey;

/**
 * Class SigningSecretKey
 * @package ParagonIE\Sapient
 */
class SigningSecretKey extends CryptographyKey
{
    /**
     * SigningSecretKey constructor.
     * @param string $key
     * @throws \RangeException
     */
    public function __construct(string $key)
    {
        if (\ParagonIE_Sodium_Core_Util::strlen($key) !== SODIUM_CRYPTO_SIGN_SECRETKEYBYTES) {
            throw new \RangeException('Key is not the correct size');
        }
        $this->key = $key;
    }

    /**
     * @return SigningSecretKey
     */
    public static function generate(): SigningSecretKey
    {
        $keypair = \ParagonIE_Sodium_Compat::crypto_sign_keypair();
        return new SigningSecretKey(
            \ParagonIE_Sodium_Compat::crypto_sign_secretkey($keypair)
        );
    }

    /**
     * @return SigningPublicKey
     */
    public function getPublicKey(): SigningPublicKey
    {
        return new SigningPublicKey(
            \ParagonIE_Sodium_Compat::crypto_sign_publickey_from_secretkey($this->key)
        );
    }
}