Standard library / crypto/rsa
crypto/rsa.ErrDecryption
Generic decryption failure; avoid disclosing failure details. Expected stdout: 'true\n'.
Formal Syntax & Structure
go syntaxgo
var ErrDecryption errorWorking Example
Example Snippetgo
package main
import ( "crypto/rand" "crypto/rsa" "crypto/sha256" "errors" "fmt")
func main() { k := must(rsa.GenerateKey(rand.Reader, 2048)) ct := must(rsa.EncryptOAEP(sha256.New(), rand.Reader, &k.PublicKey, []byte("Go"), []byte("demo"))) _, err := rsa.DecryptOAEP(sha256.New(), nil, k, ct, []byte("wrong")) fmt.Println(errors.Is(err, rsa.ErrDecryption))}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) }}