Format and remove 09.5.md spaces
This commit is contained in:
56
zh/09.5.md
56
zh/09.5.md
@@ -9,20 +9,20 @@
|
||||
Go语言对这三种加密算法的实现如下所示:
|
||||
```Go
|
||||
|
||||
//import "crypto/sha256"
|
||||
h := sha256.New()
|
||||
io.WriteString(h, "His money is twice tainted: 'taint yours and 'taint mine.")
|
||||
fmt.Printf("% x", h.Sum(nil))
|
||||
//import "crypto/sha256"
|
||||
h := sha256.New()
|
||||
io.WriteString(h, "His money is twice tainted: 'taint yours and 'taint mine.")
|
||||
fmt.Printf("% x", h.Sum(nil))
|
||||
|
||||
//import "crypto/sha1"
|
||||
h := sha1.New()
|
||||
io.WriteString(h, "His money is twice tainted: 'taint yours and 'taint mine.")
|
||||
fmt.Printf("% x", h.Sum(nil))
|
||||
//import "crypto/sha1"
|
||||
h := sha1.New()
|
||||
io.WriteString(h, "His money is twice tainted: 'taint yours and 'taint mine.")
|
||||
fmt.Printf("% x", h.Sum(nil))
|
||||
|
||||
//import "crypto/md5"
|
||||
h := md5.New()
|
||||
io.WriteString(h, "需要加密的密码")
|
||||
fmt.Printf("%x", h.Sum(nil))
|
||||
//import "crypto/md5"
|
||||
h := md5.New()
|
||||
io.WriteString(h, "需要加密的密码")
|
||||
fmt.Printf("%x", h.Sum(nil))
|
||||
|
||||
```
|
||||
单向哈希有两个特性:
|
||||
@@ -44,25 +44,25 @@ Go语言对这三种加密算法的实现如下所示:
|
||||
|
||||
```Go
|
||||
|
||||
//import "crypto/md5"
|
||||
//假设用户名abc,密码123456
|
||||
h := md5.New()
|
||||
io.WriteString(h, "需要加密的密码")
|
||||
//import "crypto/md5"
|
||||
//假设用户名abc,密码123456
|
||||
h := md5.New()
|
||||
io.WriteString(h, "需要加密的密码")
|
||||
|
||||
//pwmd5等于e10adc3949ba59abbe56e057f20f883e
|
||||
pwmd5 :=fmt.Sprintf("%x", h.Sum(nil))
|
||||
//pwmd5等于e10adc3949ba59abbe56e057f20f883e
|
||||
pwmd5 :=fmt.Sprintf("%x", h.Sum(nil))
|
||||
|
||||
//指定两个 salt: salt1 = @#$% salt2 = ^&*()
|
||||
salt1 := "@#$%"
|
||||
salt2 := "^&*()"
|
||||
//指定两个 salt: salt1 = @#$% salt2 = ^&*()
|
||||
salt1 := "@#$%"
|
||||
salt2 := "^&*()"
|
||||
|
||||
//salt1+用户名+salt2+MD5拼接
|
||||
io.WriteString(h, salt1)
|
||||
io.WriteString(h, "abc")
|
||||
io.WriteString(h, salt2)
|
||||
io.WriteString(h, pwmd5)
|
||||
//salt1+用户名+salt2+MD5拼接
|
||||
io.WriteString(h, salt1)
|
||||
io.WriteString(h, "abc")
|
||||
io.WriteString(h, salt2)
|
||||
io.WriteString(h, pwmd5)
|
||||
|
||||
last :=fmt.Sprintf("%x", h.Sum(nil))
|
||||
last :=fmt.Sprintf("%x", h.Sum(nil))
|
||||
|
||||
```
|
||||
在两个salt没有泄露的情况下,黑客如果拿到的是最后这个加密串,就几乎不可能推算出原始的密码是什么了。
|
||||
@@ -79,7 +79,7 @@ Go语言对这三种加密算法的实现如下所示:
|
||||
目前Go语言里面支持的库http://code.google.com/p/go/source/browse?repo=crypto#hg%2Fscrypt
|
||||
```Go
|
||||
|
||||
dk := scrypt.Key([]byte("some password"), []byte(salt), 16384, 8, 1, 32)
|
||||
dk := scrypt.Key([]byte("some password"), []byte(salt), 16384, 8, 1, 32)
|
||||
```
|
||||
通过上面的的方法可以获取唯一的相应的密码值,这是目前为止最难破解的。
|
||||
|
||||
|
||||
Reference in New Issue
Block a user