用于加密和解密 Message 对象的算法。
它使用 AES-256-GCM。对于非确定性加密(默认),它将生成一个随机 IV,或者对于确定性加密,它将从加密内容派生一个初始化向量。
请参阅 Cipher::Aes256Gcm。
命名空间
方法
- D
- E
- I
- K
常量
| DEFAULT_ENCODING | = | Encoding::UTF_8 |
实例公共方法
decrypt(encrypted_message, key:) 链接
解密提供的 Message。
当 key 是一个 Array 时,它将尝试所有密钥,如果都不成功,将引发一个 ActiveRecord::Encryption::Errors::Decryption。
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/encryption/cipher.rb, line 25 def decrypt(encrypted_message, key:) try_to_decrypt_with_each(encrypted_message, keys: Array(key)).tap do |decrypted_text| decrypted_text.force_encoding(encrypted_message.headers.encoding || DEFAULT_ENCODING) end end
encrypt(clean_text, key:, deterministic: false) 链接
加密提供的文本并返回加密的 Message。
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/encryption/cipher.rb, line 15 def encrypt(clean_text, key:, deterministic: false) cipher_for(key, deterministic: deterministic).encrypt(clean_text).tap do |message| message.headers.encoding = clean_text.encoding.name unless clean_text.encoding == DEFAULT_ENCODING end end
iv_length() 链接
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/encryption/cipher.rb, line 35 def iv_length Aes256Gcm.iv_length end
key_length() 链接
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/encryption/cipher.rb, line 31 def key_length Aes256Gcm.key_length end