md5sha1计算方法,就是简单的将数据的md5结果与sha1结果拼接起来。

package main

import (
    "crypto/md5"
    "crypto/sha1"

    "fmt"
    "io"
)

func main() {
    fmt.Println("go crypto md5sha1 demo.")
    str1 := "https://const.net.cn"
    str2 := "/"
    w := md5.New()
    io.WriteString(w, str1)
    io.WriteString(w, str2)

    w1 := sha1.New()
    io.WriteString(w1, str1)
    io.WriteString(w1, str2)

    hashstr := fmt.Sprintf("md5sha1 = %x%x", w.Sum(nil), w1.Sum(nil))
    fmt.Println(hashstr)
}

输出:

go run .
go crypto md5sha1 demo.
md5sha1 = 4b655b565c09136dd867a7e523371391405036731104eeb5fae59f5f600f8b4771d93ac5
echo -n "https://const.net.cn/" | openssl dgst -md5-sha1
(stdin)= 4b655b565c09136dd867a7e523371391405036731104eeb5fae59f5f600f8b4771d93ac5
本文链接地址:https://const.net.cn/55.html

标签: md5, sha1, md5sha1

添加新评论