A library providing easy methods for cryptographic operations, including key pair generation.
Go to file
2024-04-14 17:26:24 +02:00
.gitea/workflows fix(core): update 2024-02-09 17:52:13 +01:00
.vscode BREAKING CHANGE(core): switch to esm 2022-10-23 23:53:34 +02:00
test fix(core): update 2023-08-21 08:29:27 +02:00
ts fix(core): update 2024-02-09 17:53:20 +01:00
.gitignore fix(core): update 2021-02-20 17:52:21 +00:00
.gitlab-ci.yml BREAKING CHANGE(core): switch to esm 2022-10-23 23:53:34 +02:00
license fix(core): update 2019-10-01 14:11:20 +02:00
npmextra.json update tsconfig 2024-04-14 17:26:24 +02:00
package.json update tsconfig 2024-04-14 17:26:24 +02:00
pnpm-lock.yaml fix(core): update 2024-02-09 17:52:13 +01:00
readme.hints.md update tsconfig 2024-04-14 17:26:24 +02:00
readme.md update tsconfig 2024-04-14 17:26:24 +02:00
tsconfig.json fix(core): update 2024-02-09 17:52:13 +01:00

@push.rocks/smartcrypto

easy crypto methods

Install

To install @push.rocks/smartcrypto, open a terminal and run the following command:

npm install @push.rocks/smartcrypto

This will add @push.rocks/smartcrypto to your project's dependencies.

Usage

This guide demonstrates how to use @push.rocks/smartcrypto effectively by covering its main functionalities. The module offers straightforward methods for handling cryptographic operations. We'll go through generating keys, encrypting and decrypting data, and converting keys to various formats.

Setting up your project

Firstly, ensure you have a TypeScript project configured to use ES Modules. Initialize @push.rocks/smartcrypto in your project as shown:

import { Smartcrypto } from '@push.rocks/smartcrypto';

const smartCrypto = new Smartcrypto();

Generating a Key Pair

Generating a new RSA key pair is a common requirement. Let's see how @push.rocks/smartcrypto simplifies this process:

(async () => {
  const keyPair = await smartCrypto.createKeyPair();
  console.log('Public Key:', keyPair.publicKey.toPemString());
  console.log('Private Key:', keyPair.privateKey.toPemString());
})();

This asynchronous function generates a new RSA key pair and logs the PEM-formatted public and private keys. This is particularly useful for creating keys for secure communication.

Working with Public and Private Keys

You can manipulate public and private keys using their respective classes. For instance, converting a private key to a PEM string for storage or transmission is straightforward:

import { PrivateKey } from '@push.rocks/smartcrypto';

// Assuming you already have a privateKey object:
const privateKeyPemString = privateKey.toPemString();
console.log(privateKeyPemString);

Similarly, you can create a PrivateKey object from a PEM string. This is useful when you retrieve a stored key and need to use it in your application:

const privateKeyFromPem = PrivateKey.fromPemString(privateKeyPemString);

The same methods apply to public keys with the PublicKey class:

import { PublicKey } from '@push.rocks/smartcrypto';

const publicKeyPemString = publicKey.toPemString();
console.log(publicKeyPemString);

const publicKeyFromPem = PublicKey.fromPemString(publicKeyPemString);

Advanced Usage

Beyond basic key generation and format conversion, @push.rocks/smartcrypto leverages node-forge for advanced cryptographic operations. You can engage in more complex scenarios such as signing data, verifying signatures, and even using the library for SSH key generation.

// Example: Signing a message with RSA private key
const message = 'Hello, SmartCrypto!';
const signedMessage = privateKey.signMessage(message);
console.log('Signed Message:', signedMessage);

// Example: Verifying a signature with the corresponding public key
const isVerified = publicKey.verifyMessage(message, signedMessage);
console.log('Is the message verified?', isVerified);

Note: The .signMessage and .verifyMessage methods are conceptual and may require specific implementation or extension of the base classes provided by @push.rocks/smartcrypto.

Conclusion

@push.rocks/smartcrypto provides an easy-to-use interface for cryptographic operations, significantly reducing the complexity of managing keys and performing secure data transmission. The examples above showcase a subset of what's possible, encouraging you to explore further and integrate cryptography seamlessly into your Node.js applications.

For more advanced use cases and customization, refer to the node-forge documentation. @push.rocks/smartcrypto is designed to work smoothly with node-forge, enabling you to extend its functionalities according to your project's needs.

This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the license file within this repository.

Please note: The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.

Trademarks

This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.

Company Information

Task Venture Capital GmbH
Registered at District court Bremen HRB 35230 HB, Germany

For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.

By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.