我一直在使用下面的代碼在我的應用程序在過去的一年,並使用此代碼有20萬的記錄:如何在ruby中重構OpenSSL pkcs5_keyivgen?
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和加密器-1.1.3
我看到this question和this question,但他們沒有幫我解決問題。
我不知道爲什麼這是建議關閉?這是一個編程問題?你能否提供反饋意見,爲什麼你會倒下,所以我可以改善這個問題。謝謝。 – Kamilski81