Class: Tcat::EncryptionService
- Inherits:
-
Object
- Object
- Tcat::EncryptionService
- Defined in:
- lib/tcat/encryption_service.rb
Defined Under Namespace
Classes: EncryptionError
Constant Summary collapse
- CIPHER_ALGORITHM =
'AES-128-ECB'
Instance Method Summary collapse
- #encrypt(message) ⇒ Object
-
#initialize(secret_key) ⇒ EncryptionService
constructor
A new instance of EncryptionService.
Constructor Details
#initialize(secret_key) ⇒ EncryptionService
Returns a new instance of EncryptionService.
12 13 14 15 |
# File 'lib/tcat/encryption_service.rb', line 12 def initialize(secret_key) @secret_key = secret_key validate_key! end |
Instance Method Details
#encrypt(message) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/tcat/encryption_service.rb', line 17 def encrypt() cipher = setup_cipher = (, cipher.block_size) encrypted = cipher.update() Base64.strict_encode64(encrypted) rescue OpenSSL::Cipher::CipherError => e raise EncryptionError, "Encryption failed: #{e.}" rescue StandardError => e raise EncryptionError, "Unexpected error during encryption: #{e.}" end |