library: encoding/base32
This commit is contained in:
@@ -292,6 +292,7 @@ Here are the Go packages that can be imported correctly:
|
|||||||
* [reflect](https://pkg.go.dev/reflect) (partially)
|
* [reflect](https://pkg.go.dev/reflect) (partially)
|
||||||
* [time](https://pkg.go.dev/time) (partially)
|
* [time](https://pkg.go.dev/time) (partially)
|
||||||
* [encoding/binary](https://pkg.go.dev/encoding/binary)
|
* [encoding/binary](https://pkg.go.dev/encoding/binary)
|
||||||
|
* [encoding/base32](https://pkg.go.dev/encoding/base32)
|
||||||
* [encoding/base64](https://pkg.go.dev/encoding/base64)
|
* [encoding/base64](https://pkg.go.dev/encoding/base64)
|
||||||
* [regexp](https://pkg.go.dev/regexp)
|
* [regexp](https://pkg.go.dev/regexp)
|
||||||
* [regexp/syntax](https://pkg.go.dev/regexp/syntax)
|
* [regexp/syntax](https://pkg.go.dev/regexp/syntax)
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/base32"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func base64Demo() {
|
||||||
msg := "Hello, 世界"
|
msg := "Hello, 世界"
|
||||||
encoded := base64.StdEncoding.EncodeToString([]byte(msg))
|
encoded := base64.StdEncoding.EncodeToString([]byte(msg))
|
||||||
fmt.Println(encoded)
|
fmt.Println(encoded)
|
||||||
@@ -16,3 +17,20 @@ func main() {
|
|||||||
}
|
}
|
||||||
fmt.Println(string(decoded))
|
fmt.Println(string(decoded))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func base32Demo() {
|
||||||
|
str := "JBSWY3DPFQQHO33SNRSCC==="
|
||||||
|
dst := make([]byte, base32.StdEncoding.DecodedLen(len(str)))
|
||||||
|
n, err := base32.StdEncoding.Decode(dst, []byte(str))
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("decode error:", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
dst = dst[:n]
|
||||||
|
fmt.Printf("%q\n", dst)
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
base64Demo()
|
||||||
|
base32Demo()
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user