jjzjj

bash - Go Sha256Sum 与 Bash sha256sum 的区别

关闭。这个问题是notreproducibleorwascausedbytypos.它目前不接受答案。这个问题是由于错别字或无法再重现的问题引起的。虽然类似的问题可能是on-topic在这里,这个问题的解决方式不太可能帮助future的读者。关闭4年前。Improvethisquestion我的go代码生成了与bash命令行不同的sha256sum值。我通读了各种问题和答案,它们都指向我已经完成的工作,正如这个社区要求我在发帖前做的那样这是我在go上的sha256sum代码sha256Key:=verifyEmail+":"+md5password+":"+dateStrhasherS

Golang 中的 Ruby 1.9.3 Digest::SHA1.hexdigest 等价物

关闭。这个问题需要debuggingdetails.它目前不接受答案。编辑问题以包含desiredbehavior,aspecificproblemorerror,andtheshortestcodenecessarytoreproducetheproblem.这将有助于其他人回答问题。关闭5年前。Improvethisquestion如何将此方法从Ruby1.9.3复制到Golang1.7?require'digest/sha2'text=Digest::SHA1.hexdigest("Helloworld")

go - 如何使用 golang 在 git repo 中 check out 特定的 SHA

我需要帮助使用golang将代码checkout到特定SHA编号的gitrepo 最佳答案 这实际上是一个Go问题,因为它指的是go-gitlibrary.因此,您可以执行以下操作:packagemainimport("fmt"git"gopkg.in/src-d/go-git.v4""gopkg.in/src-d/go-git.v4/plumbing")//Basicexampleofhowtocheckoutaspecificcommit.funcmain(){//Clonethegivenrepositorytothegive

Go lang SHA3-256 给出无效输出?

关闭。这个问题需要detailsorclarity。它目前不接受答案。想改进这个问题吗?添加细节并通过editingthispost澄清问题。关闭5年前。Improvethisquestion我遇到了goSHA3-256函数的奇怪结果:这是sourcecodeimport("golang.org/x/crypto/sha3""encoding/hex")funcmain(){pub,_:=hex.DecodeString("c342dbf7cdd3096c4c3910c511a57049e62847dd5030c7e644bc855acc1fd626")h:=sha3.Sum256(p

戈朗 : sha256 returns two different values for the same input

我正在努力实现一些需要哈希操作的加密函数(我想计算自定义结构的哈希)所以我想使用crypto中的SHA256哈希函数golang包。但是,我注意到,当我针对同一输入多次运行哈希函数时,有时它会返回不同的值。我的理解是SHA函数为单个输入值返回相同的哈希输出。下面是我对哈希函数的实现:funcmyHash(sMyStruct)[]byte{bytes:=[]byte(fmt.Sprintf("%v",s))h:=sha256.New()h.Write(bytes)returnh.Sum(nil)}myStruct有以下字段:typeMyStructstruct{elliptic.Curv

go - sha256 和与 gzip 命令输出不匹配

我正在尝试在Go中计算一个gzip文件的sha256总和,但我的输出与gzip命令的输出不匹配。我有一个函数Compress可以压缩io.Reader的内容,在我的例子中是一个文件。funcCompress(rio.Reader)(io.Reader,error){varbufbytes.Bufferzw:=gzip.NewWriter(&buf)if_,err:=io.Copy(zw,r);err!=nil{returnnil,err}iferr:=zw.Close();err!=nil{returnnil,err}return&buf,nil}然后我有一个函数Sum256可以计算读

go - 如何在 Go 中将字节数组转换为字符串

这个问题在这里已经有了答案:HowdoIconvert[Size]bytetostringinGo?(8个答案)关闭2年前。[]byte到字符串会引发错误。string([]byte[:n])也会引发错误。顺便说一下,例如,文件名的sha1值是字符串。它是否明确需要utf-8或任何其他编码集?谢谢!

go - 使用与 node.js 或 Python 不同的结果的 Go 签名的 Hmac/sha1 消息

我正在尝试使用Go生成Hmac/SHA1签名,但我得到的结果与我使用Node.js或Python进行测试时的结果不同。这是我在Go中的代码:signature:=hmac.New(sha1.New,[]byte(signKey))signature.Write([]byte(buffer))returnhex.EncodeToString(signature.Sum(nil))这是我在Node.js中的代码:returncrypto.createHmac('sha1',signKey).update(buffer).digest('hex');python:returnhmac.new

arrays - 函数应返回 sha256/sha384/sha512 结果作为 byte slice

我正在编写一个函数,它将输入数据作为字符串和要调用的SHA算法的位大小。它应该将生成的散列作为byteslice返回(第一次尝试):packagemainimport("crypto/sha256""crypto/sha512""errors""fmt")funcmain(){input:="Thisisatest."sha256,_:=shaSum(input,256)sha384,_:=shaSum(input,384)sha512,_:=shaSum(input,512)fmt.Println(input,sha256,sha384,sha512)}funcshaSum(data

go - SHA1 encoding with secret,相当于PHP hash_hmac

我有以下PHP函数publicfunctionencodePassword($raw,$salt){returnhash_hmac('sha1',$raw.$salt,$this->secret);}我需要将其翻译成Go。我找到了以下示例,但它不涉及key。https://gobyexample.com/sha1-hashes我如何在Go中创建一个函数,它产生与PHP的hash_hmac完全相同的结果?Update:AfterLeo'sanswer,foundthisresourcewithhmacexamplesinmanylanguages:https://github.com/d