Webcryptobox
Convenient wrappers around OpenSSL to use WebCrypto compatible cryptography.
It works nicely together with the JavaScript Webcryptobox and Bash Webcryptobox.
Webcryptobox is both a library and a little command line interface. It helps with elliptic curve key generation, derivation, fingerprinting, import and export as well as AES encryption and decryption.
For the library documentation, see docs.rs/webcryptobox. In the following I describe the CLI usage.
Installation
Clone the project, compile it and use the binary:
Usage
Webcryptobox prints out usage information if you do not provide any argument, or if the command is not recognized.
Configuration
Cipher selection is done via environment variables:
CURVE: EC curve name. Defaults toP-521MODE: AES mode. Defaults toGCMLENGTH: AES key length in bits. Default is256
Supported EC Curves
P-256: 256-bit prime field Weierstrass curve. Also known assecp256r1orprime256v1.P-384: 384-bit prime field Weierstrass curve. Also known as:secp384r1oransip384r1.P-521: 521-bit prime field Weierstrass curve. Also known as:secp521r1oransip521r1.
Supported AES Modes
CBC: Cipher Block Chaining ModeGCM: Galois/Counter Mode
Supported AES Key Lengths
128256
generate-key-pair
Generate ECDH key and output private key as pem.
3A==
generate-key
Generate AES key, output as hex.
generate-iv
Generate an initialization vector, output as hex.
derive-public-key <filename>
Derive public key from private key PEM file, output public key pem.
PQr/8plzeplPomryfdw=
sha1-fingerprint <filename>
Calculate SHA-1 fingerprint from private or public key pem file, output hex. Works by hashing the DER contents of the public key part.
sha256-fingerprint <filename>
Calculate SHA-256 fingerprint from private or public key pem file, output hex. Works by hashing the DER contents of the public key part.
derive-key <private-key> <peer-key>
derive AES key from private and public key files as pem, output hex.
encrypt <key> <iv>
reads message from STDIN and key and iv as hex args, encrypts message and prints out as base64.
|
decrypt <key> <iv>
reads encrypted message in base64 format from STDIN and key and iv as hex args and prints out decrypted message.
|
derive-and-encrypt <private-key> <peer-key> <iv>
reads message from STDIN and private and public key files as pem and iv as hex and encrypts message and prints out as base64.
|
derive-and-decrypt <private-key> <peer-key> <iv>
reads encrypted message in base64 format from STDIN, private and public key files as pem and iv as hex and prints out decrypted message.
|
Test
There's a test suite which ensures the lib works as expected. Run it with cargo:
License
This package is licensed under the Apache 2.0 License.
© 2022 Johannes J. Schmidt