Standard library / crypto/rsa

crypto/rsa.PublicKey.Size()

Returns modulus length in bytes, also the size of raw RSA signatures and ciphertexts. Expected stdout: '256\n'.

Formal Syntax & Structure

go syntaxgo
func (pub *PublicKey) Size() int

Return Value

int

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.GenerateKey(rand.Reader, 2048)); fmt.Println(k.PublicKey.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