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