golang  md5 结果类型

   package main

   import (
"crypto/md5"
"encoding/hex"
"fmt"
) func main() {
data := []byte("testing")
b := md5.Sum(data)
fmt.Println(string(b)) //错误,不能直接转 string
13 // fmt.Println(hex.EncodeToString(b[:]))
14 // fmt.Println(b[:])
}
# command-line-arguments
GoProjcet/src/exercise/test_md5.go:: cannot convert b (type []byte) to type string

Note:

Also note that converting a "random" slice of bytes to a string is most likely not what you want because a "random" slice of bytes may not be a valid UTF-8 byte sequence.

Instead use the encoding/hex package to convert the result to a hex string like this:

fmt.Println(hex.EncodeToString(b[:]))

   package main

   import (
"crypto/md5"
"encoding/hex"
"fmt"
) func main() {
data := []byte("testing")
b := md5.Sum(data)
// fmt.Println(string(b))
fmt.Println(hex.EncodeToString(b[:]))
fmt.Println(b[:])
}
ae2b1fca515949e5d54fb22b8ed95575
[ ]


golang md5 结果类型的更多相关文章

  1. golang 函数作为类型

    golang 函数作为类型 package main import "fmt" type A func(int, int) func (f A)Serve() { fmt.Prin ...

  2. 学习Golang语言(6):类型--切片

    学习Golang语言(1): Hello World 学习Golang语言(2): 变量 学习Golang语言(3):类型--布尔型和数值类型 学习Golang语言(4):类型--字符串 学习Gola ...

  3. golang md5加密和python md5加密比较

    python md5加密和golang md5加密各有不同,记录于此做备忘 Python 方法 md5 import base64 import hashlib def get_md5_data(bo ...

  4. Golang 的 `[]interface{}` 类型

    Golang 的 []interface{} 类型 我其实不太喜欢使用 Go 语言的 interface{} 类型,一般情况下我宁愿多写几个函数:XxxInt, XxxFloat, XxxString ...

  5. Golang的值类型和引用类型的范围、存储区域、区别

    常见的值类型和引用类型分别有哪些? 值类型:基本数据类型 int 系列, float 系列, bool, string .数组和结构体struct,使用这些类型的变量直接指向存在内存中的值,值类型的变 ...

  6. golang md5

    package main import ( "crypto/md5" "encoding/hex" "fmt" "io" ...

  7. golang中函数类型

    今天看Martini文档,其功能列表提到完全兼容http.HandlerFunc接口,就去查阅了Go: net/http的文档,看到type HandlerFunc这部分,顿时蒙圈了.由于之前学习的时 ...

  8. golang sync.noCopy 类型 —— 初探 copylocks 与 empty struct

    问题引入 学习golang(v1.16)的 WaitGroup 代码时,看到了一处奇怪的用法,见下方类型定义: type WaitGroup struct { noCopy noCopy ... } ...

  9. [转]Golang之struct类型

    http://blog.chinaunix.net/xmlrpc.php?r=blog/article&uid=22312037&id=3756923 一.struct        ...

随机推荐

  1. linux中文件权限格式与chmod命令以及用户和用户组的管理

    简单了解一下linux中的文件权限格式与chmod命令 chmod命令:改变文件或者目录的权限 格式:chmod [参数] [<权限范围><符号><权限代码>] - ...

  2. scala学习笔记(8)

    1.trait ------------------------------- 如果只有一个trait就使用extends进行扩展,如果是多个,就使用with对生于trait进行扩展 trait lo ...

  3. install python+twisted+mysqldb+django on mac

    一. install python 1) check install or not 在mac终端输入命令:which python 即可查看python的路径 2)未安装时,手动下载安装包 地址:ht ...

  4. IIC通信协议详解

    IIC通信详解 IIC概述 IIC:两线式串行总线,它是由数据线SDA和时钟线SCL构成的串行总线,可发送和接收数据. 在CPU与被控IC之间.IC与IC之间进行双向传送,高速IIC总线一般可达400 ...

  5. Docker数据目录相关操作

    数据目录挂载 我们可以在创建容器的时候,将宿主机的目录与容器内的目录进行映射,这样我们就可以通过修改宿主机某个目录的文件从而去影响容器.使用 -v 选项 docker run -id -v /宿主机绝 ...

  6. 一、IIS搭建前端静态模板_资源加载问题

    一.模板文件说明和效果展示 二.IIS配置模板 三.解决方案 把资源文件复制到html目录内与index.htm同级,因为我iis指定站点就是该目录.

  7. strptime strftime时间函数总结

    time(2) #include <time.h> time_t time(time_t *timep);//获取当前时间距离1970-01-01 00:00:00  经历的秒数 p = ...

  8. 进行移动端rem适配

    (function (designWidth, maxWidth) { var doc = document, win = window; var docEl = doc.documentElemen ...

  9. Thread的几种方法的使用

    1:setPriority() 设置线程的优先级,从1 到10.   5是默认的.  1是最低优先级. 10是最高优先级 public class MyThread01 implements Runn ...

  10. facebook第三方登陆实践

    未完,待续... 1.注册 到Facebook官网注册开发者账号,创建应用(开发者平台 https://developers.facebook.com),如果尚未注册账号的请注册账号并进行登录) 注册 ...