修改了base64的代码

This commit is contained in:
astaxie
2012-10-30 14:20:50 +08:00
parent 5dbb0ab8c5
commit 8654c22678

15
9.6.md
View File

@@ -11,23 +11,17 @@
"fmt"
)
const (
base64Table = "123QRSTUabcdVWXYZHijKLAWDCABDstEFGuvwxyzGHIJklmnopqr234560178912"
)
var coder = base64.NewEncoding(base64Table)
func base64Encode(src []byte) []byte {
return []byte(coder.EncodeToString(src))
return []byte(base64.StdEncoding.EncodeToString(src))
}
func base64Decode(src []byte) ([]byte, error) {
return coder.DecodeString(string(src))
return base64.StdEncoding.DecodeString(string(src))
}
func main() {
// encode
hello := "hello world"
hello := "你好,世界! hello world"
debyte := base64Encode([]byte(hello))
fmt.Println(debyte)
// decode
@@ -43,6 +37,7 @@
fmt.Println(string(enbyte))
}
## 高级加解密
Go语言的`crypto`里面支持对称加密的高级加解密包有:
@@ -92,7 +87,7 @@ Go语言的`crypto`里面支持对称加密的高级加解密包有:
cfb.XORKeyStream(ciphertext, plaintext)
fmt.Printf("%s=>%x\n", plaintext, ciphertext)
// 密字符串
// 密字符串
cfbdec := cipher.NewCFBDecrypter(c, commonIV)
plaintextCopy := make([]byte, len(plaintext))
cfbdec.XORKeyStream(plaintextCopy, ciphertext)