2

我正在使用attr_encrypted,并使用我不再有权访问的密钥加密了一些数据。我想使用新密钥用新数据覆盖现有/旧数据。我怎样才能做到这一点?

例如,考虑一下:

class User
    attr_encrypted :account_number,  key: ENV['ATTR_ENCRYPTED_KEY'] # new key
end

以下尝试失败OpenSSL::Cipher::CipherError

u = User.first
u.account_number = '123456789' # error here!
u.save 

根据堆栈跟踪(如下),我认为这是由于attr_encrypted尝试decrypt首先尝试的事实 - 由于密钥不同,这显然不起作用。有没有办法规避这种情况,只需iv使用新密钥写入新数据和 ?

.../gems/encryptor-3.0.0/lib/encryptor.rb:98:in `final'
.../gems/encryptor-3.0.0/lib/encryptor.rb:98:in `crypt'
.../gems/encryptor-3.0.0/lib/encryptor.rb:49:in `decrypt'
.../bundler/gems/attr_encrypted-399c5dd168ca/lib/attr_encrypted.rb:246:in `decrypt'
.../bundler/gems/attr_encrypted-399c5dd168ca/lib/attr_encrypted.rb:335:in `decrypt'
.../bundler/gems/attr_encrypted-399c5dd168ca/lib/attr_encrypted.rb:164:in `block (2 levels) in attr_encrypted'
.../bundler/gems/attr_encrypted-399c5dd168ca/lib/attr_encrypted/adapters/active_record.rb:76:in `block in attr_encrypted'
4

0 回答 0