Standard library / crypto/rsa
crypto/rsa.PrivateKey
Holds public key (including promoted Size), secret exponent D, prime factors and precomputed values. Generate rather than constructing by hand; do not print secret fields. Expected stdout: 'true\n'.
Formal Syntax & Structure
go syntaxgo
type PrivateKey struct { PublicKey // public part. D *big.Int // private exponent Primes []*big.Int // prime factors of N, has >= 2 elements.
Precomputed PrecomputedValues}Working Example
Example Snippetgo
package main
import ( "crypto/rand" "crypto/rsa" "fmt")
func main() { k := must(rsa.GenerateKey(rand.Reader, 2048)); fmt.Println(k.Validate() == 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) }}