/** * Load a keypair from a file * * @param string $filePath * @param int $type * @return KeyPair * * @throws CryptoException\InvalidFlags */ public static function fromFile($filePath, $type = Key::CRYPTO_SIGN) { $keys = SignatureSecretKey::fromFile($filePath, $type | Key::ASYMMETRIC | Key::ENCRYPTION); return new SignatureKeyPair(...$keys); }
/** * Sign a message with our private key * * @param string $message Message to sign * @param SignatureSecretKey $privateKey * @param boolean $raw Don't hex encode the output? * @return string Signature (detached) */ public static function sign(string $message, SignatureSecretKey $privateKey, bool $raw = false) : string { $signed = \Sodium\crypto_sign_detached($message, $privateKey->getRawKeyMaterial()); if ($raw) { return $signed; } return \Sodium\bin2hex($signed); }