Standard library / crypto/rsa
crypto/rsa.VerifyPSS()
Verifies an RSA-PSS signature against a digest, public key and salt policy. Nil error means valid; modified data or wrong key fails. Options may be nil; opts.Hash is ignored, so pass the actual digest algorithm explicitly. Expected stdout: 'true\n'.
Formal Syntax & Structure
go syntaxgo
func VerifyPSS(pub *PublicKey, hash crypto.Hash, digest []byte, sig []byte, opts *PSSOptions) errorParameters & Attributes
| Name | Type | Description |
|---|---|---|
| pub | *PublicKey | Public key used for the operation. |
| hash | crypto.Hash | Hash algorithm, hash instance or digest as specified by the signature and description. |
| digest | []byte | Digest of the message. |
| sig | []byte | Signature bytes to verify. |
| opts | *PSSOptions | Algorithm-specific options; see description for nil behavior. |
Return Value
error
Result as described above; check any returned error before use.
Working Example
Example Snippetgo
package main
import ( "crypto" "crypto/rand" "crypto/rsa" "crypto/sha256" "fmt")
func main() { k := must(rsa.GenerateKey(rand.Reader, 2048)) h := sha256.Sum256([]byte("Go")) o := &rsa.PSSOptions{SaltLength: rsa.PSSSaltLengthEqualsHash, Hash: crypto.SHA256} s := must(rsa.SignPSS(rand.Reader, k, crypto.SHA256, h[:], o)) fmt.Println(rsa.VerifyPSS(&k.PublicKey, crypto.SHA256, h[:], s, o) == nil)}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) }}