SHA-2,名称来自于安全散列算法2(英语:Secure Hash Algorithm 2)的缩写,一种密码散列函数算法标准,由美国国家安全局研发,由美国国家标准与技术研究院(NIST)在2001年发布。属于SHA算法之一,是SHA-1的后继者。其下又可再分为六个不同的算法标准,包括了:SHA-224、SHA-256、SHA-384、SHA-512、SHA-512/224、SHA-512/256。

package main

import (
    "crypto/sha512"
    "fmt"
    "io"
)

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

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

输出:

go run .
go crypto sha512_256 demo.
sha512_256 = 37d0b0e1e9bc941d6e21cf3dc04bf258df77f1de2f296390d845ccb20e06ef23
echo -n "https://const.net.cn/" | openssl dgst -sha512-256
(stdin)= 37d0b0e1e9bc941d6e21cf3dc04bf258df77f1de2f296390d845ccb20e06ef23
本文链接地址:https://const.net.cn/54.html

标签: sha512

添加新评论