本文簡要介紹ruby語言中 OpenSSL::KDF.scrypt
的用法。
用法
scrypt(pass, salt:, N:, r:, p:, length:) → aString
使用基於 scrypt 密碼的 key 派生函數的給定參數從 pass
派生 key 。結果可用於密碼存儲。
scrypt 被設計為memory-hard,並且比使用 PBKDF2 或 bcrypt 等替代 KDF 更安全地抵禦使用自定義硬件的暴力攻擊。
關鍵字參數 N
、 r
和 p
可用於調整 scrypt。 RFC 7914(發布於 2016 年 8 月,tools.ietf.org/html/rfc7914#section-2)指出使用值 r=8 和 p=1 似乎會產生良好的結果。
有關詳細信息,請參閱 RFC 7914 (tools.ietf.org/html/rfc7914)。
參數
- 經過
-
密碼。
- 鹽
-
鹽。
- N
-
CPU/內存成本參數。這必須是 2 的冪。
- r
-
塊大小參數。
- p
-
並行化參數。
- 長度
-
派生 key 的八位字節長度。
示例
pass = "password"
salt = SecureRandom.random_bytes(16)
dk = OpenSSL::KDF.scrypt(pass, salt: salt, N: 2**14, r: 8, p: 1, length: 32)
p dk #=> "\xDA\xE4\xE2...\x7F\xA1\x01T"
相關用法
- Ruby KDF.hkdf用法及代碼示例
- Ruby KDF模塊用法及代碼示例
- Ruby Kernel.local_variables用法及代碼示例
- Ruby Kernel.Integer用法及代碼示例
- Ruby Kernel.binding用法及代碼示例
- Ruby Kernel.frozen?用法及代碼示例
- Ruby Kernel.`cmd`用法及代碼示例
- Ruby Kernel.autoload用法及代碼示例
- Ruby Kernel.loop用法及代碼示例
- Ruby Kernel.Hash用法及代碼示例
- Ruby Kernel.caller用法及代碼示例
- Ruby Kernel.set_trace_func用法及代碼示例
- Ruby Kernel.exit!用法及代碼示例
- Ruby Kernel.trap用法及代碼示例
- Ruby Kernel.String用法及代碼示例
- Ruby Kernel.select用法及代碼示例
- Ruby Kernel.syscall用法及代碼示例
- Ruby Kernel.then用法及代碼示例
- Ruby Kernel.sprintf用法及代碼示例
- Ruby Kernel.Pathname用法及代碼示例
- Ruby Kernel.srand用法及代碼示例
- Ruby Kernel.yield_self用法及代碼示例
- Ruby Kernel.BigDecimal用法及代碼示例
- Ruby Kernel.raise用法及代碼示例
- Ruby Kernel.test用法及代碼示例
注:本文由純淨天空篩選整理自ruby-lang.org大神的英文原創作品 KDF.scrypt。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。