用于加密和解密 Message
对象的算法。
它使用 AES-256-GCM。它将为非确定性加密(默认)生成随机 IV,或从加密内容中派生初始化向量以进行确定性加密。
参见 Cipher::Aes256Gcm
。
命名空间
方法
- D
- E
- I
- K
常量
DEFAULT_ENCODING | = | Encoding::UTF_8 |
实例公共方法
解密(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
加密(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