Module: SpamProtect::Encryption
- Defined in:
- lib/spam_protect/encryption.rb,
lib/spam_protect/encryption/payload.rb,
lib/spam_protect/encryption/secret_key.rb
Defined Under Namespace
Class Method Summary collapse
-
.decrypt(token) ⇒ Object
Decrypt and verify a token.
-
.encrypt(payload) ⇒ Object
Encrypt and sign a payload (hash).
- .secret_key ⇒ Object
Class Method Details
.decrypt(token) ⇒ Object
Decrypt and verify a token. Returns the payload (usually a Hash) or nil.
14 15 16 17 |
# File 'lib/spam_protect/encryption.rb', line 14 def decrypt(token) encryptor = ActiveSupport::MessageEncryptor.new(secret_key) encryptor.decrypt_and_verify(token) end |
.encrypt(payload) ⇒ Object
Encrypt and sign a payload (hash). Returns a token string or nil on failure.
8 9 10 11 |
# File 'lib/spam_protect/encryption.rb', line 8 def encrypt(payload) encryptor = ActiveSupport::MessageEncryptor.new(secret_key) encryptor.encrypt_and_sign(payload) end |
.secret_key ⇒ Object
19 20 21 |
# File 'lib/spam_protect/encryption.rb', line 19 def secret_key SecretKey.relevant_key! end |