Skip to content

Initializer

init(modulus:exponent:privateExponent:)

Initializes a new RSA.PrivateKey instance with modulus, exponent, and private exponent.
init(modulus: String, exponent: String, privateExponent: String) throws

Parameters

modulus

The modulus of the RSA key, represented as a base64 URL encoded string.

exponent

The exponent of the RSA key, represented as a base64 URL encoded string.

Discussion

This convenience initializer creates an RSA key using the modulus, exponent, and private exponent. All these parameters are expected to be base64 URL encoded strings.

Throws

  • JWTError/generic with the identifier RSAKey if either the modulus or exponent cannot be decoded from their base64 URL encoded strings.

  • RSAError/keyInitializationFailure if there is a failure in initializing the RSA key, especially when the private key components are involved.

  • RSAError/keySizeTooSmall if the key size is less than 2048 bits.

Note

  • The provided modulus and exponent are key components for creating RSA public keys.

  • The private exponent is an additional parameter required for creating RSA private keys.