diff --git a/9.6.md b/9.6.md index 124c626c..c506d8d1 100644 --- a/9.6.md +++ b/9.6.md @@ -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)