在Go语言中生成私钥时使用什么类型的读取器?

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

What type of Reader to use when generating a Private Key in Go?

问题

我需要在Go中生成一个私钥。我正在使用rsa包(http://golang.org/pkg/crypto/rsa/)。特别是,我似乎想使用GenerateKey方法。该方法的一个参数是io.Reader类型(http://golang.org/pkg/io/#Reader),但似乎有许多不同类型的读取器。使用一种类型的Reader是否有任何优势?谢谢!

英文:

I need to generate a private key in Go. I am using the rsa package (http://golang.org/pkg/crypto/rsa/). In particular, it seems that I would like to use the GenerateKey method. One of the parameters for this method is of type io.Reader (http://golang.org/pkg/io/#Reader), but it seems like there are many different types of readers. Is there any advantage to using one type of Reader over another? Thanks!

答案1

得分: 5

我相信在这种特殊情况下,适合的io.Reader可能是crypto/rand.Reader

var Reader io.Reader

Reader是一个全局共享的强加密伪随机生成器实例。在类Unix系统上,Reader从/dev/urandom读取。在Windows系统上,Reader使用CryptGenRandom API。

英文:

I believe that in this particular case the suitable io.Reader would be, for example, crypto/rand.Reader.

> var Reader io.Reader
>
>Reader is a global, shared instance of a cryptographically strong pseudo-random generator. On Unix-like systems, Reader reads from /dev/urandom. On Windows systems, Reader uses the CryptGenRandom API.

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

发表评论

匿名网友

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

确定