英文:
Working with digital signatures in Go
问题
我想在我用Go语言编写的程序中使用签名,但是我无法理解文档,文档在这里。特别是,我想使用SignPKCS1v15
和VerifyPKCS1v15
函数,但是我不确定需要传递什么参数。如果有这两个函数的示例代码,我将受益匪浅。谢谢。
注意:我想要发送的消息是我定义的一个结构体。
英文:
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
结尾,通常具有有意义的名称,并且位于实际实现特定包的代码所在的相同目录中。
因此,在你的特定情况下,你可以这样做:
- 下载与你的编译器版本匹配的Go源代码包,并将其解压到某个位置。
- 导航到与你感兴趣的包相匹配的目录。标准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:
- Download the Go source package of the version matching your compiler (what
go version
shows) and unpack it somewhere. - 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 thesrc/pkg/crypto/rsa
directory.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论