mirror of
https://github.com/jagandeepbrar/lunasea.git
synced 2026-08-31 12:42:34 +00:00
NEW - [Settings/Modules] Add an information/help button with module descriptions and links TWEAKS - [Radarr] Always show the amount of days content will be available instead of limiting it to only content in the next 30 days - [Settings] Moved "Backup & Restore" and "Logs" to "System" section - [Settings] Merged "Customization" and "Modules" sections into "Configuration" - [Settings/Sonarr] Removed the need to enable Sonarr to test the connection - [Settings/Tautulli] Removed the need to enable Tautulli to test the connection FIXES - [IAPs] Ensure all IAPs are marked as "consumed" - [Flutter] Updated packages - [Logging] Updated Sentry to v4 framework to improve capturing fatal/crashing bugs - [Settings/Logs] Hide exception and stack trace buttons when an error is not available - [Sonarr/History] Fixed history fetching the oldest entries, not the newest - [State] Correctly clear state when clearing LunaSea's configuration - [Tautulli/Activity] Fixed consistency of hardware transcoding indicator compared to the web UI - [UI/Divider] Fix consistency of divider width across regular and AMOLED dark theme
44 lines
2.0 KiB
Dart
44 lines
2.0 KiB
Dart
import 'package:encrypt/encrypt.dart';
|
|
import 'package:lunasea/core.dart';
|
|
|
|
class LunaEncryption {
|
|
static const int _IV_LENGTH = 16;
|
|
static const int _KEY_LENGTH = 32;
|
|
static const String _PAD_VALUE = '0';
|
|
static const String ENCRYPTION_FAILURE = '<<INVALID_ENCRYPTION>>';
|
|
|
|
/// Encrypt a given string using a given encryption key, and return the encrypted string.
|
|
///
|
|
/// The key is duped, and either trimmed or padded (with _PAD_VALUE) to 32 characters.
|
|
String encrypt(String encryptionKey, String data) {
|
|
try {
|
|
String morphedKey = (encryptionKey+encryptionKey).padRight(_KEY_LENGTH, _PAD_VALUE).substring(0, _KEY_LENGTH);
|
|
Key key = Key.fromUtf8(morphedKey);
|
|
IV iv = IV.fromLength(_IV_LENGTH);
|
|
final _encrypter = Encrypter(AES(key));
|
|
final _encrypted = _encrypter.encrypt(data, iv: iv).base64;
|
|
return _encrypted;
|
|
} catch (error, stack) {
|
|
LunaLogger().error('Failed to decrypted "$data" with using key "$encryptionKey"', error, stack);
|
|
}
|
|
return ENCRYPTION_FAILURE;
|
|
}
|
|
|
|
/// Decrypt a given string using a given encryption key, and return the decrypted string.
|
|
///
|
|
/// The key is duped, and either trimmed or padded (with _PAD_VALUE) to 32 characters.
|
|
String decrypt(String decryptionKey, String data) {
|
|
try {
|
|
String morphedKey = (decryptionKey+decryptionKey).padRight(_KEY_LENGTH, _PAD_VALUE).substring(0, _KEY_LENGTH);
|
|
Key key = Key.fromUtf8(morphedKey);
|
|
IV iv = IV.fromLength(_IV_LENGTH);
|
|
final _encrypter = Encrypter(AES(key));
|
|
return _encrypter.decrypt64(data, iv: iv);
|
|
} catch (error) {
|
|
/// Do not log as error (to Sentry), since a decrpytion error is very likely a user problem
|
|
LunaLogger().warning('LunaEncryption', 'decrypt', 'Failed to decrypted "$data" with using key "$decryptionKey"');
|
|
}
|
|
return ENCRYPTION_FAILURE;
|
|
}
|
|
}
|