Standard library / crypto/rsa
crypto/rsa.PSSOptions
SaltLength sets salt policy; Hash overrides the SignPSS hash argument when nonzero and is required for PrivateKey.Sign. Expected stdout: 'true\n'.
Formal Syntax & Structure
go syntaxgo
type PSSOptions struct { SaltLength int
Hash crypto.Hash}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) }}