本文簡要介紹ruby語言中 OpenSSL::PKey::DH類
的用法。
Diffie-Hellman key 交換協議的實現基於有限域中的離散對數,與 DSA
的構建基礎相同。
Diffie-Hellman 參數的訪問器方法
- Kernel.p
-
Diffie-Hellman 參數的素數(
OpenSSL::BN
)。 - DH#g
-
Diffie-Hellman 參數的生成器(
OpenSSL::BN
)g。 - DH#pub_key
-
與私鑰匹配的每會話公鑰(
OpenSSL::BN
)。這需要傳遞給DH#compute_key
。 - DH#priv_key
-
每個會話的私鑰,
OpenSSL::BN
。
key 交換示例
# you may send the parameters (der) and own public key (pub1) publicly
# to the participating party
dh1 = OpenSSL::PKey::DH.new(2048)
der = dh1.to_der
pub1 = dh1.pub_key
# the other party generates its per-session key pair
dhparams = OpenSSL::PKey::DH.new(der)
dh2 = OpenSSL::PKey.generate_key(dhparams)
pub2 = dh2.pub_key
symm_key1 = dh1.compute_key(pub2)
symm_key2 = dh2.compute_key(pub1)
puts symm_key1 == symm_key2 # => true
相關用法
- Ruby DH.public_key用法及代碼示例
- Ruby DH.generate_key!用法及代碼示例
- Ruby DH.new用法及代碼示例
- Ruby Date.valid_civil?用法及代碼示例
- Ruby DateTime jisx0301()用法及代碼示例
- Ruby Date cwday()用法及代碼示例
- Ruby Date ctime()用法及代碼示例
- Ruby Date.gregorian?用法及代碼示例
- Ruby DRb.regist_server用法及代碼示例
- Ruby Date asctime()用法及代碼示例
- Ruby DateTime類用法及代碼示例
- Ruby DateTime.hour用法及代碼示例
- Ruby DateTime.jd用法及代碼示例
- Ruby DateTime.zone用法及代碼示例
- Ruby DateTime ordinal()用法及代碼示例
- Ruby DateTime.second用法及代碼示例
- Ruby Date.strftime用法及代碼示例
- Ruby Digest.update用法及代碼示例
- Ruby DSA.export用法及代碼示例
- Ruby DSA.to_pem用法及代碼示例
- Ruby DNS.new用法及代碼示例
- Ruby Document.new用法及代碼示例
- Ruby Date.valid_ordinal?用法及代碼示例
- Ruby DateTime to_datetime()用法及代碼示例
- Ruby DateTime civil()用法及代碼示例
注:本文由純淨天空篩選整理自ruby-lang.org大神的英文原創作品 DH類。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。