Class: Onlylogs::SecureFilePath
- Inherits:
-
Object
- Object
- Onlylogs::SecureFilePath
- Defined in:
- app/models/onlylogs/secure_file_path.rb
Defined Under Namespace
Classes: SecurityError
Class Method Summary collapse
Class Method Details
.decrypt(encrypted_path) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'app/models/onlylogs/secure_file_path.rb', line 16 def self.decrypt(encrypted_path) decoded = Base64.urlsafe_decode64(encrypted_path) encryptor = ActiveSupport::MessageEncryptor.new(encryption_key) encryptor.decrypt_and_verify(decoded) rescue => e Rails.logger.error "Onlylogs: Decryption failed: #{e.message}" raise SecurityError, "Invalid encrypted file path" end |
.encrypt(file_path) ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'app/models/onlylogs/secure_file_path.rb', line 7 def self.encrypt(file_path) encryptor = ActiveSupport::MessageEncryptor.new(encryption_key) encrypted = encryptor.encrypt_and_sign(file_path.to_s) Base64.urlsafe_encode64(encrypted).tr("=", "") rescue => e Rails.logger.error "Onlylogs: Encryption failed for #{file_path}: #{e.message}" raise SecurityError, "Encryption failed" end |
.encryption_key ⇒ Object
27 28 29 |
# File 'app/models/onlylogs/secure_file_path.rb', line 27 def self.encryption_key Rails.application.secret_key_base[0..31] end |