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. SpringBoot自定义配置步骤

    1. 在yml中填写自定义配置 ly: sms: accessKeyId: # 短信配置 accessKeySecret: signName: xx商城 # 签名名称 verifyCodeTempla ...

  2. 16.Linux-CentOS系统进入单用户模式修改root用户密码操作

    问题描述: root用户密码忘记,进入单用户重置root用户密码 解决步骤: 1.重启服务器,在系统显示内核版本界面后“按E键”,进入内核启动项2.找到Linux16这一行段,将“ro”修改成“rw” ...

  3. 时钟管脚设置问题 xilinx ERROR:Place:864 - Incompatible IOB's are locked to the same bank 0

    ERROR:Place:1108 - A clock IOB / BUFGMUX clock component pair have been found   that are not placed ...

  4. 判断是否是iframe框架打开登录页, iframe框架着顶部页面刷新

    if (window != top) top.location.href = location.href;

  5. hdu 1506 单调栈

    #include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) memset((a),b,sizeof(a)) #defin ...

  6. JavaScript设计模式 样例三 —— 装饰模式

    装饰模式(Decorator Pattern): 定义:在不改变原对象的情况下,动态的给对象添加一些额外的职责.就功能而言,装饰模式相比生成子类更为灵活. 目的:把类的核心职责和装饰功能区分开.可以去 ...

  7. L3-006. 迎风一刀斩

    迎着一面矩形的大旗一刀斩下,如果你的刀够快的话,这笔直一刀可以切出两块多边形的残片.反过来说,如果有人拿着两块残片来吹牛,说这是自己迎风一刀斩落的,你能检查一下这是不是真的吗? 注意摆在你面前的两个多 ...

  8. vue开发使用vue-particles如何兼容IE11?

    最近开发vue项目,项目有一个粒子特效使用vue-particles.项目用vue-cli构建,webpack打包完毕,丢到服务器,chrome访问完美,测试360和Edge也正常.遗憾的是,在IE1 ...

  9. man clock

    CLOCK(3)   Linux程序员手册   CLOCK(3) 名称  时钟-确定处理器时间 简介  #include <time.h>    clock_t clock(void);  ...

  10. 【leetcode】845. Longest Mountain in Array

    题目如下: 解题思路:本题的关键是找出从升序到降序的转折点.开到升序和降序,有没有联想的常见的一个动态规划的经典案例--求最长递增子序列.对于数组中每一个元素的mountain length就是左边升 ...