Nodes/ComfyUI ARG Toolkit/RSA Private Numbers into Key
ComfyUI Node

RSA Private Numbers into Key

Rebuild a private key from p, q and d (mind the output labels)

By AzelusLightvale·Created about a year ago·Updated a day ago· 3
RSA Private Numbers into Key
  • public_numbers
  • public_key
  • private_numbers
◄var_p1►
◄var_q1►
◄private_exponent65537►
◄skip_rsa_key_validationfalse►

You have the guts of an RSA private key - the two primes and the private exponent - but no key file. RSA Private Numbers into Key turns them back into a working key object you can hand to RSA Decrypt Data. It's the "assemble a key from parts" node, and in a puzzle graph it's usually the payoff at the end of a chain: recover the primes, derive the exponent, rebuild the key, decrypt the message.

Why a key needs three numbers and not one

A private key is (n, e, d) - modulus, public exponent, private exponent. But the efficient form of RSA, and the one every library uses, works on the factorization: with p and q you can decrypt with CRT, which is several times faster, and you get n as a byproduct. pyca's RSAPrivateNumbers therefore wants seven fields: p, q, d, the public numbers, and the three CRT parameters dmp1, dmq1, iqmp.

This node spares you the arithmetic. Look at the source and it computes those three itself:

pvn_iqmp = rsa.rsa_crt_iqmp(var_p, var_q)
pvn_dmp1 = rsa.rsa_crt_dmp1(private_exponent, var_p)
pvn_dmq1 = rsa.rsa_crt_dmq1(private_exponent, var_q)

So you supply three values and it fills in the rest. That's genuinely convenient, and it's also why the node can't sanity-check much on its own - it trusts what you gave it.

Inputs

public_numbers (NUMOBJ, required) is the odd one out: you can't just give p, q and d, you need the public half too. Get it from RSA Public Numbers into Key (its public_numbers output) or from RSA Private Numbers Values, which also emits the public numbers container - practically, that means the modulus and exponent you were handed in the first place.

Then the three you probably care about: var_p and var_q are the two primes (the order doesn't matter much, the CRT helpers handle it), and private_exponent is d. If you have p, q and e but not d, RSA Restore Private Exponent computes it for you.

skip_rsa_key_validation defaults to off and the author's tooltip is blunt about why to leave it: skipping validation loads faster but is unsafe and "may cause OpenSSL to misbehave or crash, potentially dragging ComfyUI down with it." Take that at face value. If a key fails validation, the interesting bug is upstream in your numbers, not in the validation.

All three numeric fields are widgets capped at 4,294,967,296 - a 32-bit ceiling - so real 2048-bit material has to arrive over wires from nodes like RSA Private Numbers Values or RSA Restore Prime Factors, not from typing. This node is realistically for small numbers and for wired-together graphs.

Outputs, and a labeling bug worth knowing

The declared outputs are public_key (KEYOBJ) and private_numbers (NUMOBJ). In the 2.3.5 source the actual return is return (private_num, private_key) - the numbers container first, the key object second. So as shipped, the socket named public_key hands you numbers and the socket named private_numbers hands you the key.

Wire it, run it, and if a downstream node complains about receiving the wrong object type, swap the two. And note the private-key output - whichever socket it's on - is what RSA Decrypt Data wants; there's no separately-named private key output here, which is confusing until you remember the return tuple is mislabeled.

Install

cd ComfyUI/custom_nodes
git clone https://github.com/AzelusLightvale/ComfyUI-ARG-Toolkit
pip install -r requirements.txt

Or via Manager: search ComfyUI ARG Toolkit, install, restart ComfyUI, refresh the browser. No models. The pinned requirements.txt includes torch and torchaudio, so a manual install can clobber your CUDA torch build - Manager is the gentler route, and if you go manual, re-check torch.cuda.is_available() after.

Common issues

Validation error on key creation. Your p, q and d don't actually correspond - p * q must equal the modulus in public_numbers, and d must be the inverse of e. Recover them with the pack's own recovery nodes rather than recomputing by hand in a text editor.

Wrong object downstream. The output-label swap above. Try the other socket before you start debugging your numbers.

You can't type the key in. The 32-bit widget cap. Feed integers from other nodes' outputs.

The whole of ComfyUI crashed. Almost certainly skip_rsa_key_validation set true plus bad numbers, which is exactly the failure the tooltip warns about.

CategoryARG Toolkit/Cryptography/Modern/Asymmetric

Inputs (5)

NameTypeDefaultDescription
public_numbersNUMOBJAs a requirement to generate one of these keys, you need the public numbers generated from that key as well.
var_pINT11–4294967296One of the two primes composing the private modulus `n`
var_qINT11–4294967296One of the two primes composing the private modulus `n`
private_exponentINT655371–4294967296The private exponent (d).
skip_rsa_key_validationBOOLEANfalseUnless you know what you're doing, do not change this. Disabling RSA key validation speeds up key loading, but is **unsafe** and may cause OpenSSL to misbehave or crash, potentially dragging ComfyUI down with it.

Outputs (2)

NameTypeDescription
public_keyKEYOBJ—
private_numbersNUMOBJ—