mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-27 19:19:21 +03:00
Bugfix: Crypt crash when Sodium not installed
This commit is contained in:
parent
9f1e9f1899
commit
fdc0e3f59f
1 changed files with 14 additions and 10 deletions
|
|
@ -95,18 +95,22 @@ abstract class Crypt
|
|||
{
|
||||
$data = \json_encode($data);
|
||||
|
||||
try {
|
||||
$nonce = \random_bytes(\SODIUM_CRYPTO_AEAD_XCHACHA20POLY1305_IETF_NPUBBYTES);
|
||||
return ['sodium', $nonce, static::SodiumEncrypt($data, $nonce, $key)];
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Crypt', 'Sodium ' . $e->getMessage());
|
||||
if (\is_callable('sodium_crypto_aead_xchacha20poly1305_ietf_decrypt')) {
|
||||
try {
|
||||
$nonce = \random_bytes(\SODIUM_CRYPTO_AEAD_XCHACHA20POLY1305_IETF_NPUBBYTES);
|
||||
return ['sodium', $nonce, static::SodiumEncrypt($data, $nonce, $key)];
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Crypt', 'Sodium ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
$iv = \random_bytes(\openssl_cipher_iv_length(static::$cipher));
|
||||
return ['openssl', $iv, static::OpenSSLEncrypt($data, $iv, $key)];
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Crypt', 'OpenSSL ' . $e->getMessage());
|
||||
if (\is_callable('openssl_encrypt')) {
|
||||
try {
|
||||
$iv = \random_bytes(\openssl_cipher_iv_length(static::$cipher));
|
||||
return ['openssl', $iv, static::OpenSSLEncrypt($data, $iv, $key)];
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Crypt', 'OpenSSL ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
$salt = \random_bytes(16);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue