Cryptography

DH Key Exchange

Diffie-Hellman Key Exchange
对数难算,利用 x^b%c同余a已知c,x,b算a容易,但是已知a,x,c算b难的特点不好破解
DH算法用于确定一个临时用的密钥(双方都不用长时间保存私钥太久,下次通信可以重新生成,所以安全),该公钥可以之后用于对称加密
可能被中间人攻击,阻塞,重演,或者质数取得太短,被number field sieve这个算出b
https://baike.baidu.com/item/Diffie-Hellman/9827194?fromtitle=Diffie–Hellman&fromid=6611182&fr=aladdin
https://en.wikipedia.org/wiki/Diffie–Hellman_key_exchange
https://en.wikipedia.org/wiki/General_number_field_sieve
更安全的有椭圆曲率的
https://en.wikipedia.org/wiki/Elliptic-curve_Diffie–Hellman

Hash

md5 sha1
用于验证密码
Hash 防止数据库泄露明文密码完全没有存于数据库的必要
Hash+相同Salt 防止现存的字典攻击
Hash+Salt 每个不同可以存于数据库 防止同时针对所有密码的字典攻击

AES

Advanced Encryption Standard
用于通信
https://baike.baidu.com/item/aes/5903?fr=aladdin
除了AES还有早期的不安全的DES和安全改进过渡用的DES3(慢)
https://security.stackexchange.com/questions/26179/security-comparsion-of-3des-and-aes
key3种大小
10 rounds for 128-bit keys.
12 rounds for 192-bit keys.
14 rounds for 256-bit keys.
区块大小都是128位=44matrix8bit
对明文矩阵块进行3轮
key异或
查找表替换
行移位
列混淆
https://blogs.msdn.microsoft.com/shawnfa/2006/10/09/the-differences-between-rijndael-and-aes
https://docs.microsoft.com/en-us/dotnet/api/system.security.cryptography.aes?view=netframework-4.8

RSA

用于证书,包含身份信息,密码存储
Rivest-Shamir-Adleman
1.pq互质
2.n=pq
3.r=lcm(p-1,q-1)最小公倍数
4.找一个e (1<e<r)使得 e,r互质
5.求d
e%r同余1中的d
public key:(e,n)
private key:(d,n)
加密:c=m^e%n
解密:m=c^d%n

Digit Singal

用于确认对方是对方
有官方认证机构帮你授权,包裹你的内容,别人能确认你的内容是认证过的,并且认证信息是你的域名
你的内容或者hash后的内容通过私钥加密,然后别人通过你的公钥解密确认或验证签名,因为要先解一层官方认证机构,所以是可靠的

一个PGP(Pretty Good Privacy)的crptosystem上面的可以都用到
同时要考虑哪个场景适合哪个,比如效率,安全性

原文地址:https://www.cnblogs.com/HaibaraAi/p/10819437.html