golang中的hash函数

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

内容简介: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


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

查看所有标签

猜你喜欢:

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

Ajax Design Patterns

Ajax Design Patterns

Michael Mahemoff / O'Reilly Media / 2006-06-29 / USD 44.99

Ajax, or Asynchronous JavaScript and XML, exploded onto the scene in the spring of 2005 and remains the hottest story among web developers. With its rich combination of technologies, Ajax provides a s......一起来看看 《Ajax Design Patterns》 这本书的介绍吧!

在线进制转换器
在线进制转换器

各进制数互转换器

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

UNIX 时间戳转换

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试