Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DH算法实现公私钥生成与交换 #17

Open
lynhao opened this issue Aug 20, 2021 · 0 comments
Open

DH算法实现公私钥生成与交换 #17

lynhao opened this issue Aug 20, 2021 · 0 comments

Comments

@lynhao
Copy link
Owner

lynhao commented Aug 20, 2021

因为RSA不具备前向安全,当服务器的秘钥要破解之后,以前的加密数据也可以被解析出来, 而DH是在每次TLS握手时都随机生成对称秘钥,从而保证了前向安全(或者说前向保密)

流程

发送方:
随机生成一个基数g, 一个整数p, 一个发送方的随机生成的秘密整数a, 生成一个公钥A
A = g^a mod p, 然后将生成的公钥发送给接收方
接收方:
同样生成一个秘密整数b,然后拿到发送方的公钥,可以生产一个接收方的公钥B
B = g^b mod p, 然后将生成的公钥发送给发送方

这个时候发送方和接收方都有彼此的公私钥,然后生成共同秘钥K

发送方: k = B^a mode p
接收方: k = A^b mode p

例如

协定使用p = 23, 基数g = 5

client: 秘密整数 a=6, A = g^a mode p = 5^6%23 = 8
server: 秘密整数 b=15, B = g^b mode p = 5^15%23 = 19

生成最终的共同秘钥K
client: k = 19^6%23 = 2
server: k = 8^15%23 = 2

中间人攻击

当中间人假装自己是服务端,进行了一次DH秘钥交换, 与此同时中间人再假装自己是客户端跟服务端通信,又进行了一次DH秘钥交换

解决方式: 使用KPI证书, 达到身份验证即可解决

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant