【发布时间】:2013-07-26 13:42:53
【问题描述】:
过去一年我一直在我的应用程序中使用以下代码,并且使用此代码有 200k 记录:
options = { :algorithm => 'aes-256-cbc', :value => "changethis", :key => "secretkey" }
cipher = OpenSSL::Cipher::Cipher.new(options[:algorithm])
cipher.send(:encrypt)
cipher.pkcs5_keyivgen(options[:key])
result = cipher.update(options[:value])
result << cipher.final
# => "x\xED\x14s\xFD\x0E\x97\xC5\x996[M\x1E\x94\xDEI"
我需要(按业务)重构pkcs5_keyivgen 部分,以正确执行:例如,
options = { :algorithm => 'aes-256-cbc', :value => "changethis", :key => "secretkey" }
cipher = OpenSSL::Cipher::Cipher.new(options[:algorithm])
cipher.send(:encrypt)
cipher.key = '' # ??? 1) How does pkcs5_keyivgen in above code generate key, or does it just use my options[:key]
cipher.iv = '' # ??? 2) How does pkcs5_keyivgen in above code generate iv
result = cipher.update(options[:value])
result << cipher.final
我必须弄清楚pkcs5_keyivgen 如何设置key 和iv。想法在这里?我们正在使用 ruby-1.9.3-p286 和 encryptor-1.1.3
我看到了this question和this question,但他们并没有帮我解决问题。
【问题讨论】:
-
我不知道为什么建议关闭它?这是一个编程问题?请您反馈一下您为什么投反对票,以便我改进问题。谢谢。