Nodes/comfyui-encrypt/RSA Key Generator
ComfyUI Node

RSA Key Generator

Mint an RSA key pair in ComfyUI (and keep the private half out of your workflow JSON)

By SilentZhang·Created 10 months ago·Updated 10 months ago· 1
RSA Key Generator
    • private_key_pem
    • public_key_pem
    key_size
    private_key_path
    public_key_path

    You can't do anything with the pack's RSAEncryptNode until you have a key, and this is how you get one. RSAKeyGeneratorNode mints a fresh RSA key pair, hands you both halves as PEM strings, and optionally writes them to disk. One click, two keys, done. It's the front door of the comfyui-encrypt pack - a tiny, obscure utility, but the first thing you'll reach for when you try the workflow.

    How it works

    Under the hood it calls the cryptography library's generate_private_key with exponent 65537, then exports the private key as PKCS#8 PEM with no passphrase and the public key as SubjectPublicKeyInfo PEM. Every run is a fresh random pair - there's no caching, no "regenerate if exists," so run it once and treat that output as your one and only key. Wire public_key_pem straight into RSAEncryptNode, and keep the private half somewhere safe.

    The inputs and outputs that matter

    • key_size (required): 2048 or 4096. The README pushes 4096 "for stronger security," which is technically true and practically overkill for most people. 2048 is still the industry default and noticeably faster to generate and encrypt with; if you're just getting a render to a collaborator, either is fine. Choose 4096 if you're paranoid or the data actually matters.
    • private_key_path / public_key_path (optional): if set, the node writes each key to that file. Leave them blank and the keys only exist as node outputs - which is a bigger deal than it sounds, see below.
    • Outputs: private_key_pem and public_key_pem (both STRING): the two PEM blobs. They're plain text, so you can read them off the node, paste them into a string node, or just wire the public one forward.

    The two things that will bite you

    First, the private key has no passphrase. The code writes it with NoEncryption() - that's a plaintext PEM sitting on disk (or in your graph). Anyone who gets that file gets the key, full stop. Save it somewhere with real file permissions, and don't leave it in a shared folder.

    Second, and this one catches people: saving your workflow embeds the key in the JSON. ComfyUI stores node values in the workflow file, so the private key string you see on screen becomes part of the saved JSON - and remember, workflow JSON rides along inside PNG metadata by default. If you generate keys only in-graph and never write them to disk, treat the saved workflow like a secret. That's a strong argument for using the path inputs so the keys live in files you control instead of in every .png you save.

    Installing it

    Same as the rest of the pack:

    cd ComfyUI/custom_nodes
    git clone https://github.com/SilentZhang/comfyui-encrypt
    

    restart ComfyUI (or use ComfyUI Manager and search comfyui-encrypt), and it appears under Encryption. The only real dependency is cryptography - Pillow and numpy already ship with ComfyUI, and install.py runs pip automatically on first load. No models, no heavy anything. If the node throws on import, cryptography didn't install; run pip install cryptography in your ComfyUI environment and reload.

    One honest note: there's no decrypt node in this pack, so the private key you generate here is only useful outside the graph - the README's Python scripts handle the decrypt side. Generate, encrypt, then decrypt with the library. It's an unusual flow, but the key node itself works exactly as labeled.

    CategoryEncryption

    Inputs (3)

    NameTypeDefaultDescription
    key_sizeCOMBO2 options: 2048, 4096
    private_key_pathoptSTRING
    public_key_pathoptSTRING

    Outputs (2)

    NameTypeDescription
    private_key_pemSTRING
    public_key_pemSTRING