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. vue 模拟去哪网

    模拟项目中遇到的问题,总结如下: 1.争对轮播图 使用vue-awesome-swiper npm install vue-awesome-swiper@2.6.7 --save //因为此版本稳定 ...

  2. Comet OJ - Contest #0 A题 解方程 (数学)

    题目描述 小象同学在初等教育时期遇到了一个复杂的数学题,题目是这样的: 给定自然数 nn,确定关于 x, y, zx,y,z 的不定方程 \displaystyle \sqrt{x - \sqrt{n ...

  3. ES6 Module(模块)

    1.export命令 一个模块就是一个独立的文件. 该文件内部的所有变量,外部无法获取. 如果你希望外部能够读取模块内部的某个变量,就必须使用export关键字输出该变量. 下面是一个 JS 文件,里 ...

  4. 【leetcode】1155. Number of Dice Rolls With Target Sum

    题目如下: You have d dice, and each die has f faces numbered 1, 2, ..., f. Return the number of possible ...

  5. CSS元素居中汇总

    总结实现不同类型元素居中的几种方法: 一.把margin值设置为auto(实现水平居中) 可以实现元素水平居中对齐 原理:使  margin-left=margin-right  如果设置  marg ...

  6. PHP入门培训教程 PHP 数据类型

    PHP 支持八种原始类型(type),下面兄弟连PHP培训 小编来给大家列出:. 四种标量类型: string(字符串) integer(整型) float(浮点型,也作 double ) boole ...

  7. 超赞的Linux软件分享(持续更新)

    开发 Android studio - Android 的官方 IDE:Android Studio 提供在各种类型的安卓设备上构建应用最快的工具. Aptana - Aptana Studio 利用 ...

  8. (容量超大)or(容量及价值)超大背包问题 ( 折半枚举 || 改变 dp 意义 )

    题意 : 以下两个问题的物品都只能取有且只有一次 ① 给你 N 个物品,所有物品的价值总和不会超过 5000, 单个物品的价格就可达 10^10 ,背包容量为 B ② 给你 N (N ≤ 40 ) 个 ...

  9. ARIMA模型--粒子群优化算法(PSO)和遗传算法(GA)

    ARIMA模型(完整的Word文件可以去我的博客里面下载) ARIMA模型(英语:AutoregressiveIntegratedMovingAverage model),差分整合移动平均自回归模型, ...

  10. vim 复制

    要复制到别的地方,用 "+y 来复制,注意是三个字符.gg"+yG 1.复制 1)单行复制 在命令模式下,将光标移动到将要复制的行处,按“yy”进行复制: 2)多行复制 在命令模式 ...