Standard library / crypto/rsa
crypto/rsa.DecryptPKCS1v15()
Legacy interoperability only; PKCS#1 v1.5 encryption is vulnerable to padding-oracle attacks. Use OAEP or a reviewed hybrid protocol for new designs. Decrypts a legacy ciphertext; avoid exposing validity to a remote caller. Expected stdout: 'Go\n'.
Formal Syntax & Structure
go syntaxgo
func DecryptPKCS1v15(random io.Reader, priv *PrivateKey, ciphertext []byte) ([]byte, error)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| random | io.Reader | Cryptographically secure random source; see description for exceptions. |
| priv | *PrivateKey | Private key used for the operation. |
| ciphertext | []byte | Encrypted message bytes. |
Return Value
([]byte, error)
Result as described above; check any returned error before use.
Working Example
Example Snippetgo
package main
import ( "crypto/rand" "crypto/rsa" "fmt")
func main() { // Historical interoperability demonstration only. Prefer modern protocols for new designs. k := must(rsa.GenerateKey(rand.Reader, 2048)) ct := must(rsa.EncryptPKCS1v15(rand.Reader, &k.PublicKey, []byte("Go"))) p := must(rsa.DecryptPKCS1v15(nil, k, ct)) fmt.Println(string(p))}func must[T any](v T, e error) T { if e != nil { panic(e) } return v}func check(e error) { if e != nil { panic(e) }}