SHA256与ripemd160两种算法应用

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/The_Reader/article/details/82972612
package main

import (
	"crypto/sha256"
	"fmt"
	"encoding/hex"
	"golang.org/x/crypto/ripemd160"
)

func main() {

	hashed := sha256.New()
	hashed.Write([]byte("i am wek"))
	hash := hashed.Sum(nil)
	fmt.Println(hex.EncodeToString(hash))

	//b490155d7ea44ef79d54ec821daca0931ba8367151364a8a4be088a2d0ff3c66
	//在线进行测试比对
	//b490155d7ea44ef79d54ec821daca0931ba8367151364a8a4be088a2d0ff3c66

	hashed2:= ripemd160.New()
	hashed2.Write([]byte("i am wek"))
	hash2 := hashed2.Sum(nil)
	fmt.Println(hex.EncodeToString(hash2))
	
	//984a5c75e441d944f4ca94f0d838b9bc425d0df9
	//在线进行测试比对
	//984a5c75e441d944f4ca94f0d838b9bc425d0df9

}

 sha256可以直接调用,ripemd160不可以直接调用,需要提前安装第三方包,golang.org/x/crypto

然后再调用。

猜你喜欢

转载自blog.csdn.net/The_Reader/article/details/82972612