golang中的hash函数

栏目: 数据库 · 发布时间: 5年前

内容简介:go语言中提供了MD5、SHA-1等几种哈希函数,下面这个例子是使用MD5和SHA-1值来对内容加密:输出结果为:

go语言中提供了MD5、SHA-1等几种哈希函数,下面这个例子是使用MD5和SHA-1值来对内容加密:

package main

import (
    "crypto/md5"
    "crypto/sha1"
    "fmt"
)

func main() {
    TestString := "Hi, pandaman!"

    Md5Inst := md5.New()
    Md5Inst.Write([]byte(TestString))
    Result := Md5Inst.Sum([]byte(""))
    fmt.Printf("%x\n\n", Result)

    Sha1Inst := sha1.New()
    Sha1Inst.Write([]byte(TestString))
    Result = Sha1Inst.Sum([]byte(""))
    fmt.Printf("%x\n\n", Result)
}

输出结果为:

golang中的hash函数

屏幕快照 2018-09-10 下午10.54.12.png


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Head First Rails

Head First Rails

David Griffiths / O'Reilly Media / 2008-12-30 / USD 49.99

Figure its about time that you hop on the Ruby on Rails bandwagon? You've heard that it'll increase your productivity exponentially, and allow you to created full fledged web applications with minimal......一起来看看 《Head First Rails》 这本书的介绍吧!

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具