草庐IT

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 - 使用与 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

cryptography - Golang 使用 ecdsa 和来自 SHA224 摘要的私钥进行签名

我需要签署一条消息以提交给远程服务(通过websocket)。为此,我需要根据一个整数(我的用户ID)和一个密码(一个base64编码的字符串)构建一个私钥,并使用SHA224进行哈希处理。为此,我使用golang和crypto/ecdsa以及用于字节编码等的随附包。这是我的文档:SignaturesuseanEllipticCurveDigitalSignatureAlgorithm(ECDSA)encodedmessagecontaining:userID,ServerNonce,ClientNodeandPrivatekey.Privatekeysaregeneratedhash

javascript - 如何将此代码从 golang 转换为 crypto hmac sha256 hex 中的 reactjs

Golang代码如下funcGenerateClientToken(secret,user,timestamp,infostring)string{token:=hmac.New(sha256.New,[]byte(secret))token.Write([]byte(user))token.Write([]byte(timestamp))token.Write([]byte(info))returnhex.EncodeToString(token.Sum(nil))}我如何将其转换为reactjs代码。我正在尝试这样importCryptoJSfrom'crypto-js'gener

Golang crypto/sha256 - 相同的输入产生不同的输出

我对Golang的crypto/sha256包有疑问。我将相同的输入发送到sha256.Sum256两次,每次输出都不同。我的代码如下://RuntheHMAC-SHA256onthegivenkmacandmessageandreturnthegeneratedMACtagfuncPCSSHA256(kmac[]byte,message[]byte)[32]byte{//NOTE:bitwiseXOR^onlyworksonintegers.kmac64:=append(kmac,[]byte(strings.Repeat("0",48))[0:]...)//Padtoobtaina

go - 如何使用 go-git 查找 sha of origin/master?

我正在尝试使用go-git查找origin/master的SHA1,在我已经完成了与gitfetch--all等效的操作之后。然而,go-git似乎不支持:gitls-remotegit@github.com:StevenACoffman/toolbox.gitgitrev-parseorigin/master有没有其他方法可以使用go-git确定origin/master的SHA1? 最佳答案 糟糕!支持gitrev-parse!使用./main.go$PWDorigin/master执行以下命令:///usr/bin/envgo

go - undefined <type float32 has no field or method sum> 错误。如何解决?

这是我的程序。当我运行它时,它给出了以下错误-a.sumundefined(typefloat32hasnofieldormethodsum)packagemainimport("fmt")typeCalculationinterface{operation(input[]float32)}typeAdditionstruct{sumfloat32}func(aAddition)operation(input[]float32){a.sum=input[0]for_,a:=rangeinput[1:]{a.sum+=a}fmt.Println("Sum:",a.sum)}funcmai

gcc - 如何修复对 `nettle_sha256_digest` 的 undefined reference ?

长话短说我正在尝试构建一个使用此依赖项的go项目:https://github.com/mqu/openldap,它又在外部链接lldap和llber库,后者又使用lgnutls,而lgnutls使用lnettle,这就是我遇到的问题。gobuild生成一长串undefinedreference,并且构建失败。这是一个示例:/usr/lib/x86_64-linux-gnu/libgnutls.a(sha-x86-ssse3.o):Infunction`_ctx_init':(.text+0x468):undefinedreferenceto`nettle_sha256_digest'