-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBoxSeal.php
66 lines (62 loc) · 1.44 KB
/
BoxSeal.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php declare(strict_types=1);
/*
* This file is part of Aplus Framework Crypto Library.
*
* (c) Natan Felles <natanfelles@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Framework\Crypto;
use SensitiveParameter;
use SodiumException;
/**
* Class BoxSeal.
*
* @package crypto
*/
class BoxSeal
{
use BoxTrait;
/**
* Encrypts a message with an anonymous public key.
*
* @param string $message
* @param string $publicKey
*
* @see BoxTrait::makePublicKey()
*
* @throws SodiumException
*
* @return string
*/
public static function encrypt(
#[SensitiveParameter]
string $message,
#[SensitiveParameter]
string $publicKey
) : string {
return \sodium_crypto_box_seal($message, $publicKey);
}
/**
* Decrypts a message ciphertext.
*
* @param string $ciphertext
* @param string $keyPair
*
* @see BoxTrait::makeKeyPair()
*
* @throws SodiumException
*
* @return false|string The message or false if the ciphertext could not be
* decrypted
*/
public static function decrypt(
#[SensitiveParameter]
string $ciphertext,
#[SensitiveParameter]
string $keyPair
) : false | string {
return \sodium_crypto_box_seal_open($ciphertext, $keyPair);
}
}