在Go中使用数字签名进行工作

huangapple go评论97阅读模式
英文:

Working with digital signatures in Go

问题

我想在我用Go语言编写的程序中使用签名,但是我无法理解文档,文档在这里。特别是,我想使用SignPKCS1v15VerifyPKCS1v15函数,但是我不确定需要传递什么参数。如果有这两个函数的示例代码,我将受益匪浅。谢谢。

注意:我想要发送的消息是我定义的一个结构体。

英文:

I would like to use signatures for a program that I am writing in Go, but I can't figure out the documentation, which is here. In particular, I would like to use the SignPKCS1v15 and VerifyPKCS1v15 functions, but I'm not sure exactly what I have to pass as arguments. I would greatly benefit from some example code of these two functions. Thanks.

Note: The message that I would like to send is a struct that I defined.

答案1

得分: 1

我认为Go源代码树中的src\pkg\crypto\rsa\pkcs1v15_test.go文件应该是一个很好的起点。

更新:为了提供更多上下文... Go源代码包含了许多用于其标准库中代码的测试(crypto/rsa包是其中的一部分),所以每当你不知道如何使用一个标准包(或者实际上是任何其他Go包)时,一个好的起点是查看涉及该包的测试,因为测试代码自然地使用了该包!测试文件以_test.go结尾,通常具有有意义的名称,并且位于实际实现特定包的代码所在的相同目录中。

因此,在你的特定情况下,你可以这样做:

  1. 下载与你的编译器版本匹配的Go源代码包,并将其解压到某个位置。
  2. 导航到与你感兴趣的包相匹配的目录。标准Go包的代码位于顶级目录下的“pkg”目录中,因此如果你对crypto/rsa包感兴趣,你需要src/pkg/crypto/rsa目录。
英文:

I think the src\pkg\crypto\rsa\pkcs1v15_test.go file in the Go source tree should be a good start.

An update striving provide more context… Go source contains many tests for the code in its standard library (and the crypto/rsa package is a part of it), so whenever you have no idea how to use a standard package (or, actually, any other Go package), a good place to start is to look at the tests involving that package as testing code naturally uses the package! Tests are kept in files ending in _test.go, usually have meaningful names and are located in the same directories actual code implementing a particular package is kept.

So in your particular case you could do this:

  1. Download the Go source package of the version matching your compiler (what go version shows) and unpack it somewhere.
  2. Navigate to the directory matching the package of interest. Code for standard Go packages is located in the "pkg" directory under the "src" top-level directory, so if you're interested in the crypto/rsa package, you need the src/pkg/crypto/rsa directory.

huangapple
  • 本文由 发表于 2013年4月30日 12:32:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/16292210.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定