Standard library / crypto/rsa

crypto/rsa.SignPSS()

Signs a precomputed digest with randomized RSA-PSS. Hash and digest length must agree; set salt policy explicitly for interoperable protocols. Options may be nil; nonzero opts.Hash overrides the hash argument. Expected stdout: 'true\n'.

Formal Syntax & Structure

go syntaxgo
func SignPSS(rand io.Reader, priv *PrivateKey, hash crypto.Hash, digest []byte, opts *PSSOptions) ([]byte, error)

Parameters & Attributes

NameTypeDescription
randio.ReaderCryptographically secure random source; see description for exceptions.
priv*PrivateKeyPrivate key used for the operation.
hashcrypto.HashHash algorithm, hash instance or digest as specified by the signature and description.
digest[]byteDigest of the message.
opts*PSSOptionsAlgorithm-specific options; see description for nil behavior.

Return Value

([]byte, 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(len(s) == k.Size())}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)  }}
Go Reference