golang md5 结果类型
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 结果类型的更多相关文章
- golang 函数作为类型
golang 函数作为类型 package main import "fmt" type A func(int, int) func (f A)Serve() { fmt.Prin ...
- 学习Golang语言(6):类型--切片
学习Golang语言(1): Hello World 学习Golang语言(2): 变量 学习Golang语言(3):类型--布尔型和数值类型 学习Golang语言(4):类型--字符串 学习Gola ...
- golang md5加密和python md5加密比较
python md5加密和golang md5加密各有不同,记录于此做备忘 Python 方法 md5 import base64 import hashlib def get_md5_data(bo ...
- Golang 的 `[]interface{}` 类型
Golang 的 []interface{} 类型 我其实不太喜欢使用 Go 语言的 interface{} 类型,一般情况下我宁愿多写几个函数:XxxInt, XxxFloat, XxxString ...
- Golang的值类型和引用类型的范围、存储区域、区别
常见的值类型和引用类型分别有哪些? 值类型:基本数据类型 int 系列, float 系列, bool, string .数组和结构体struct,使用这些类型的变量直接指向存在内存中的值,值类型的变 ...
- golang md5
package main import ( "crypto/md5" "encoding/hex" "fmt" "io" ...
- golang中函数类型
今天看Martini文档,其功能列表提到完全兼容http.HandlerFunc接口,就去查阅了Go: net/http的文档,看到type HandlerFunc这部分,顿时蒙圈了.由于之前学习的时 ...
- golang sync.noCopy 类型 —— 初探 copylocks 与 empty struct
问题引入 学习golang(v1.16)的 WaitGroup 代码时,看到了一处奇怪的用法,见下方类型定义: type WaitGroup struct { noCopy noCopy ... } ...
- [转]Golang之struct类型
http://blog.chinaunix.net/xmlrpc.php?r=blog/article&uid=22312037&id=3756923 一.struct ...
随机推荐
- MongoDB的使用学习之(五)Spring集成MongoDB以及简单的CRUD
这篇文章不错:Spring Data - MongoDB 教程 (1.0.0.M1)http://miller-cn.iteye.com/blog/1258859 1.介绍 之前在很多地方一直见到这个 ...
- 45. Jump Game II (JAVA)
Given an array of non-negative integers, you are initially positioned at the first index of the arra ...
- Spring基础18——通过注解配置bean之间的关联关系
1.组件装配 <context:component-scan>元素还会自动注册AutowiredAnnotaionBeanPostProcessor实例,这是一个bean的后置处理器,该实 ...
- Linux架构之Nginx 高可用
第53章 Nginx之高可用Keepalived 一.Keepalived高可用基本概述 1.1)什么是高可用 一般是指2台机器启动着完全相同的业务系统,当有一台机器down机了,另外一台服务器就能快 ...
- 2019长安大学ACM校赛网络同步赛 M LCM (数论)
链接:https://ac.nowcoder.com/acm/contest/897/M来源:牛客网 LCM 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65 ...
- GUI学习之二十——QAbstractSlider学习总结
今天学习一种全新的输入控件——QAbstractSlider()滑块控件的基础控件. 一.描述: QAbstractSlider()是QWidget()的子类,提供了一个范围内的整数值.它是QSlid ...
- python 文件操作、shutil模块
参考自:https://www.cnblogs.com/alex3714/articles/5717620.html 1. 文件基础操作 f = open('test.txt') #打开文件 firs ...
- SpringBoot使用Easypoi导出excel示例
SpringBoot使用Easypoi导出excel示例 https://blog.csdn.net/justry_deng/article/details/84842111
- 【NOIP2015模拟11.3】IOIOI卡片占卜
题目 K理事长很喜欢占卜,经常用各种各样的方式进行占卜.今天,他准备使用正面写着"I",反面写着"O"的卡片为今年IOI的日本代表队占卜最终的成绩. 占卜的方法 ...
- py-R-FCN的caffe配置(转)
参考:https://blog.csdn.net/wei_guo_xd/article/details/74451443 下载程序,git clone https://github.com/Orpin ...