Standard library / crypto/rsa

crypto/rsa.GenerateMultiPrimeKey()

Deprecated multi-prime RSA generation; interoperability and security trade-offs make ordinary two-prime GenerateKey preferable. This example only checks a disposable three-prime key. Expected stdout: 'true\n'.

Formal Syntax & Structure

go syntaxgo
func GenerateMultiPrimeKey(random io.Reader, nprimes int, bits int) (*PrivateKey, error)

Parameters & Attributes

NameTypeDescription
randomio.ReaderCryptographically secure random source; see description for exceptions.
nprimesintNumber of prime factors.
bitsintRequested modulus bit length.

Return Value

(*PrivateKey, error)

Result as described above; check any returned error before use.

Working Example

Example Snippetgo
package main
import (  "crypto/rand"  "crypto/rsa"  "fmt")
func main() {  k := must(rsa.GenerateMultiPrimeKey(rand.Reader, 3, 2048))  fmt.Println(len(k.Primes) == 3 && 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)  }}
Go Reference