Skip to content
moxon home

Asymmetric

The /asymmetric endpoint performs RSA asymmetric key generation, encryption, and decryption.

posthttps://api.moxon.dev/v6/asymmetric
Try itpost/v6/asymmetric

Parameters

The request body must be JSON:

  • action"keygen" | "encrypt" | "decrypt"required

    Action to perform: keygen, encrypt, or decrypt

  • textstringconditional

    Text to encrypt, or base64 ciphertext to decrypt

  • publicKeystringconditional

    PEM public key (required for encrypt)

  • privateKeystringconditional

    PEM private key (required for decrypt)

  • modulusLength"2048" | "4096"optional

    RSA key size for keygen: 2048 (default) or 4096. Ignored for encrypt/decrypt — the size limit is derived from the actual key

  • algorithm"rsa-oaep-sha256" | "rsa-oaep-sha1"optional

    Padding algorithm: rsa-oaep-sha256 (default) or rsa-oaep-sha1

Available Actions

ActionDescription
keygenGenerates an RSA key pair and returns both PEM-encoded public and private keys
encryptEncrypts text with the public key using OAEP padding and returns the result as base64
decryptDecrypts a base64 ciphertext with the private key and returns the original plaintext

Plaintext Size Limit

OAEP padding reserves space inside each RSA block, so the maximum plaintext size depends on the key size and hash algorithm:

Key SizeAlgorithmMax Plaintext
2048rsa-oaep-sha256190 bytes
2048rsa-oaep-sha1214 bytes
4096rsa-oaep-sha256446 bytes
4096rsa-oaep-sha1470 bytes

The formula is: modulusLength / 8 − 2 × hashLength − 2.

Code Examples

Response Fields

keygen action:

  • actionstring

    keygen

  • algorithmstring

    Padding algorithm used

  • modulusLengthnumber

    RSA key size in bits

  • publicKeystring

    PEM-encoded public key (SPKI)

  • privateKeystring

    PEM-encoded private key (PKCS#8)

encrypt / decrypt action:

  • actionstring

    Action performed (encrypt or decrypt)

  • algorithmstring

    Padding algorithm used

  • resultstring

    Base64 ciphertext, or decrypted plaintext

Error Handling

If parameters are missing or invalid, the API will return an error:

  • 400Action must be "keygen", "encrypt", or "decrypt"The action value is not valid
  • 400Unsupported algorithm. Use one of: rsa-oaep-sha256, rsa-oaep-sha1The algorithm value is not supported
  • 400Modulus length must be 2048 or 4096The modulusLength is not 2048 or 4096
  • 400Text is requiredThe text parameter is missing for encrypt
  • 400Public key is requiredThe publicKey is missing for encrypt
  • 400Invalid public key formatThe publicKey does not start with the PEM header, or cannot be parsed as a valid key
  • 400Text exceeds maximum length for this key size and algorithm (N bytes)The plaintext is too large for the key/algorithm
  • 400Encryption failed: invalid key or data too largeThe encryption failed
  • 400Encrypted data is requiredThe text parameter is missing for decrypt
  • 400Private key is requiredThe privateKey is missing for decrypt
  • 400Invalid private key formatThe privateKey does not start with the PEM header
  • 400Invalid key or corrupted dataThe decryption failed