tom_tools
A thin home for one-off Tom developer command-line tools; today a single `key_generator` that emits a fresh 2048-bit RSA keypair as PEM PKCS#1 keys, built on `tom_crypto`.
Overview
From the module readme.md file:
What it enables
Enables RSA keypair generation, Development signing keys, JWT-signing key material.
Relationships
Standalone β no declared relationships.
Tom Tools
> Part of the Tom framework by al-the-bear. > Β© 2024β2026 Peter Nicolai Alexis Kyaw β BSD-3-Clause, see LICENSE.
Small command-line tools for the Tom framework. Currently an RSA keypair generator that prints PEM PKCS#1 public and private keys, built on
tom_crypto.
---
Overview
tom_tools is a thin home for one-off developer command-line utilities that don't warrant a package of their own. Today it ships a single tool:
-
key_generatorβ generate a fresh 2048-bit RSA keypair and print both keys
in PEM PKCS#1 form (the -----BEGIN PUBLIC KEY----- / -----BEGIN PRIVATE KEY-----
envelope), ready to paste into a config file, a secret store, or a JWT-signing setup.
The heavy lifting is done by tom_crypto's
RsaKeyHelper; this package is just the CLI front-end. If you need to generate keys inside
your own Dart code rather than from the command line, call RsaKeyHelper directly (see Generating keys in Dart code) β you don't need
tom_tools for that.
> The private key is a secret. key_generator prints the private
key to > stdout. Redirect it straight into a protected file and never commit it or paste > it into a shared channel β see
Handling the output.
---
Installation
This is a workspace-internal package (publish_to: none); it is consumed by path, not from pub.dev:
dependencies:
tom_tools:
path: ../../basics/tom_tools
It depends (by path) on tom_crypto
for RsaKeyHelper, plus pointycastle / asn1lib / cryptography
for the underlying RSA primitives. Requires the Dart SDK ^3.9.2.
In practice you rarely depend on tom_tools β you run its tool from a checkout of the package (see
Running the key generator).
---
Features
| Capability | Entrypoint | Notes |
|---|---|---|
| Generate an RSA keypair | lib/key_generator.dart (main) |
Prints PEM PKCS#1 public + private keys to stdout |
| Reuse the generator in code | tom_crypto's RsaKeyHelper |
The same helper the CLI wraps β call it directly |
---
Quick start
Run the key generator from a checkout of the package:
cd tom_ai/basics/tom_tools
dart pub get
dart run lib/key_generator.dart
Output β a freshly generated keypair (the key bodies are random on every run, and abbreviated here with
β¦):
Public Key
-----BEGIN PUBLIC KEY-----
MIIBCgKCAQEAhIX014nch7ZGsf0tV5UK/yBwxeIrytl1TC3DKuyTB+homRawwHqβ¦
-----END PUBLIC KEY-----
Private Key
-----BEGIN PRIVATE KEY-----
MIIFowIBAAKCAQEAhIX014nch7ZGsf0tV5UK/yBwxeIrytl1TC3DKuyTB+homRaβ¦
-----END PRIVATE KEY-----
Each run produces a brand-new keypair β there is no seed or fixed output.
---
Usage
Running the key generator
key_generator is a plain main() in lib/key_generator.dart, so you run it by file path with
dart run:
dart run lib/key_generator.dart
It prints two PEM blocks to stdout: the public key first (under the line Public Key), then the private key (under
Private Key). Both use the PKCS#1 envelope produced by RsaKeyHelper.encodePublicKeyToPemPKCS1
/ encodePrivateKeyToPemPKCS1.
Handling the output
Because the private key is printed to stdout, capture it directly into a protected file rather than letting it scroll past in a shared terminal:
# Capture the whole keypair into one file, then restrict it.
dart run lib/key_generator.dart > keypair.pem
chmod 600 keypair.pem # restrict before anyone else can read it
Then split the two PEM blocks into separate files as your tooling needs. Never commit the private key
or paste it into chat/issue trackers β treat keypair.pem like any other credential.
Generating keys in Dart code
If you want a keypair inside an application rather than from the command line, skip tom_tools
entirely and call tom_crypto's RsaKeyHelper directly β it is exactly what the CLI wraps:
import 'package:pointycastle/asymmetric/api.dart';
import 'package:tom_crypto/tom_crypto.dart';
Future<void> main() async {
final keypair =
await RsaKeyHelper.computeRSAKeyPair(RsaKeyHelper.getSecureRandom());
final publicPem = RsaKeyHelper.encodePublicKeyToPemPKCS1(
keypair.publicKey as RSAPublicKey);
final privatePem = RsaKeyHelper.encodePrivateKeyToPemPKCS1(
keypair.privateKey as RSAPrivateKey);
// ... store publicPem / privatePem securely; never log the private key.
}
See the tom_crypto README
for the full RSA surface β encryption, signing, and PEM parsing back into key objects.
---
Architecture
tom_tools (workspace-internal CLI package)
β
βββ lib/key_generator.dart main(): print PEM PKCS#1 public + private keys
β
βββ delegates all crypto to
package:tom_crypto
βββ RsaKeyHelper
βββ getSecureRandom() seeded CSPRNG
βββ computeRSAKeyPair(random) 2048-bit RSA keypair
βββ encodePublicKeyToPemPKCS1(k) PEM (PKCS#1) public key
βββ encodePrivateKeyToPemPKCS1(k) PEM (PKCS#1) private key
| File / member | Role |
|---|---|
lib/key_generator.dart |
The CLI entrypoint β generates a keypair and prints both PEM blocks |
RsaKeyHelper (from tom_crypto) |
Does the actual key generation and PEM encoding |
tom_tools carries no logic of its own beyond wiring stdout to RsaKeyHelper; it is intentionally minimal.
---
Ecosystem
tom_tools is one of the foundational packages under tom_ai/basics/. All
tom_ai/basics/ packages share a single repository, tom_basics. It builds directly on
tom_crypto, the framework's cryptography library (JWT, password hashing, RSA), and exists to give that library's RSA keygen a one-command front-end.
---
Further documentation
- LICENSE β BSD-3-Clause licence text.
-
tom_cryptoβ the cryptography librarykey_generatorwraps;
full RSA / JWT / password-hashing surface. - CHANGELOG.md β release history.
---
Status
Stable (1.0.1). Workspace-internal (publish_to: none), consumed by path. A deliberately small package: one CLI tool wrapping
tom_crypto's RsaKeyHelper. dart analyze is clean. The generator runs against the live
tom_crypto RSA primitives β every invocation produces a fresh keypair.
License
BSD 3-Clause License Copyright (c) 2024-2026, Peter Nicolai Alexis Kyaw Find me on LinkedIn under Alexis Kyaw All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.