Standard library / crypto/rsa
crypto/rsa.SignPKCS1v15()
Creates deterministic PKCS#1 v1.5 signatures of a prehashed message. Use only when required by protocol; prefer PSS for new RSA signature designs. Random argument is ignored in Go 1.23. Expected stdout: 'true\n'.
Formal Syntax & Structure
go syntaxgo
func SignPKCS1v15(random io.Reader, priv *PrivateKey, hash crypto.Hash, hashed []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. |
| hash | crypto.Hash | Hash algorithm, hash instance or digest as specified by the signature and description. |
| hashed | []byte | Digest of the message. |
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")) s := must(rsa.SignPKCS1v15(rand.Reader, k, crypto.SHA256, h[:])) 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) }}