go - 如何在 golang 中正确使用 crypto/rsa Decrypt 函数?

标签 go rsa

func (priv *PrivateKey) Decrypt(rand io.Reader, ciphertext []byte, opts crypto.DecrypterOpts) (plaintext []byte, err error)

以上是 golang crypto/rsa 库中的函数。 我不太明白这里对参数opts 的解释。

Decrypt decrypts ciphertext with priv. If opts is nil or of type *PKCS1v15DecryptOptions then PKCS#1 v1.5 decryption is performed. Otherwise opts must have type *OAEPOptions and OAEP decryption is done.

我想知道我应该将什么 opts 值传递给这个函数?

最佳答案

DecryptOpts 可以是以下之一:

根据您传入的内容,rsa.Decrypt 将调用 DecryptOAEPDecryptPKCS1v15 (有或没有 session key )。

您可以在 rsa package examples 中找到有关如何使用这些选项的示例.

您要使用哪些选项完全取决于加密时选择的填充。

以后可以随时查看source for rsa.Decrypt ,很清楚它可以处理什么。

关于go - 如何在 golang 中正确使用 crypto/rsa Decrypt 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48106852/

相关文章:

Go:加载证书,使其成为 *x509.Certificate(能够签署其他证书)

go - 如何将私钥添加到证书

c# - 在 C# 中解密 RSA 编码的消息

Go空接口(interface)类型断言和创建副本

amazon-web-services - 为 Amazon Aurora 启用数据 API

go - 为什么从零 channel 读取会增加Goroutine的数量?

java - 您可以将 RSA 公共(public)指数设置为您选择的值吗?

c - _fopen$UNIX2003 引用自 OpenSSL 问题

c++ - 在 Crypto++ 中加载 PEM 编码的私有(private) RSA key

android - 在 Android 中加密,在 PHP 中使用 phpseclib 解密