Class: EasyCrypto::Crypto
- Inherits:
-
Object
- Object
- EasyCrypto::Crypto
- Defined in:
- lib/easycrypto/crypto.rb
Constant Summary collapse
- KEY_BITS =
256- AES_MODE =
:GCM- IV_LEN =
12
Instance Method Summary collapse
Instance Method Details
#encrypt_with_key(key, plaintext) ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/easycrypto/crypto.rb', line 11 def encrypt_with_key(key, plaintext) validate_key_type(key) iv = OpenSSL::Random.random_bytes(Crypto::IV_LEN) cipher = create_cipher(key, iv) encrypted = cipher.update(plaintext) + cipher.final Base64.strict_encode64(key.salt + iv + encrypted + cipher.auth_tag) end |