mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-05 15:37:03 +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);
|
$data = \json_encode($data);
|
||||||
|
|
||||||
try {
|
if (\is_callable('sodium_crypto_aead_xchacha20poly1305_ietf_decrypt')) {
|
||||||
$nonce = \random_bytes(\SODIUM_CRYPTO_AEAD_XCHACHA20POLY1305_IETF_NPUBBYTES);
|
try {
|
||||||
return ['sodium', $nonce, static::SodiumEncrypt($data, $nonce, $key)];
|
$nonce = \random_bytes(\SODIUM_CRYPTO_AEAD_XCHACHA20POLY1305_IETF_NPUBBYTES);
|
||||||
} catch (\Throwable $e) {
|
return ['sodium', $nonce, static::SodiumEncrypt($data, $nonce, $key)];
|
||||||
Log::error('Crypt', 'Sodium ' . $e->getMessage());
|
} catch (\Throwable $e) {
|
||||||
|
Log::error('Crypt', 'Sodium ' . $e->getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
if (\is_callable('openssl_encrypt')) {
|
||||||
$iv = \random_bytes(\openssl_cipher_iv_length(static::$cipher));
|
try {
|
||||||
return ['openssl', $iv, static::OpenSSLEncrypt($data, $iv, $key)];
|
$iv = \random_bytes(\openssl_cipher_iv_length(static::$cipher));
|
||||||
} catch (\Throwable $e) {
|
return ['openssl', $iv, static::OpenSSLEncrypt($data, $iv, $key)];
|
||||||
Log::error('Crypt', 'OpenSSL ' . $e->getMessage());
|
} catch (\Throwable $e) {
|
||||||
|
Log::error('Crypt', 'OpenSSL ' . $e->getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$salt = \random_bytes(16);
|
$salt = \random_bytes(16);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue