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/sha256"
    "fmt"
    "io"
)

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

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

输出:

go run .
go crypto sha256 demo.
sha256 = 2249a0aa015fa72b155b297b331bc0e7e34052096c43297d9a2de3a2df38bded
echo -n "https://const.net.cn/" | openssl dgst -sha256
(stdin)= 2249a0aa015fa72b155b297b331bc0e7e34052096c43297d9a2de3a2df38bded
本文链接地址:https://const.net.cn/50.html

标签: sha256

添加新评论