Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
016ae2a7b3 | |||
2fff5eec4b | |||
3aa4678053 | |||
1344695d46 | |||
0b2f66e0fd | |||
6e53d69194 | |||
5129377992 | |||
316470fd97 | |||
6c464b047d |
6
dist_ts/index.d.ts
vendored
6
dist_ts/index.d.ts
vendored
@ -1,6 +0,0 @@
|
||||
export * from './smartcrypto.classes.smartcrypto.js';
|
||||
export * from './smartcrypto.classes.keypair.js';
|
||||
export * from './smartcrypto.classes.privatekey.js';
|
||||
export * from './smartcrypto.classes.publickey.js';
|
||||
import { nodeForge } from './smartcrypto.plugins.js';
|
||||
export { nodeForge };
|
@ -1,7 +0,0 @@
|
||||
export * from './smartcrypto.classes.smartcrypto.js';
|
||||
export * from './smartcrypto.classes.keypair.js';
|
||||
export * from './smartcrypto.classes.privatekey.js';
|
||||
export * from './smartcrypto.classes.publickey.js';
|
||||
import { nodeForge } from './smartcrypto.plugins.js';
|
||||
export { nodeForge };
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxjQUFjLHNDQUFzQyxDQUFDO0FBQ3JELGNBQWMsa0NBQWtDLENBQUM7QUFDakQsY0FBYyxxQ0FBcUMsQ0FBQztBQUNwRCxjQUFjLG9DQUFvQyxDQUFDO0FBRW5ELE9BQU8sRUFBRSxTQUFTLEVBQUUsTUFBTSwwQkFBMEIsQ0FBQztBQUVyRCxPQUFPLEVBQUUsU0FBUyxFQUFFLENBQUMifQ==
|
11
dist_ts/smartcrypto.classes.keypair.d.ts
vendored
11
dist_ts/smartcrypto.classes.keypair.d.ts
vendored
@ -1,11 +0,0 @@
|
||||
import { PublicKey } from './smartcrypto.classes.publickey.js';
|
||||
import { PrivateKey } from './smartcrypto.classes.privatekey.js';
|
||||
export declare class KeyPair {
|
||||
static createNewKeyPair(): Promise<KeyPair>;
|
||||
publicKey: PublicKey;
|
||||
privateKey: PrivateKey;
|
||||
constructor(optionsArg: {
|
||||
privateKey: PrivateKey;
|
||||
publicKey: PublicKey;
|
||||
});
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
import * as plugins from './smartcrypto.plugins.js';
|
||||
import { PublicKey } from './smartcrypto.classes.publickey.js';
|
||||
import { PrivateKey } from './smartcrypto.classes.privatekey.js';
|
||||
export class KeyPair {
|
||||
// STATIC
|
||||
static async createNewKeyPair() {
|
||||
const done = plugins.smartpromise.defer();
|
||||
const rsa = plugins.nodeForge.pki.rsa;
|
||||
rsa.generateKeyPair({ bits: 2048, workers: 2 }, async (err, keypair) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
throw err;
|
||||
}
|
||||
done.resolve(new KeyPair({
|
||||
privateKey: new PrivateKey(keypair.privateKey),
|
||||
publicKey: new PublicKey(keypair.publicKey),
|
||||
}));
|
||||
});
|
||||
return done.promise;
|
||||
}
|
||||
constructor(optionsArg) {
|
||||
this.privateKey = optionsArg.privateKey;
|
||||
this.publicKey = optionsArg.publicKey;
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjcnlwdG8uY2xhc3Nlcy5rZXlwYWlyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRjcnlwdG8uY2xhc3Nlcy5rZXlwYWlyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxPQUFPLE1BQU0sMEJBQTBCLENBQUM7QUFDcEQsT0FBTyxFQUFFLFNBQVMsRUFBRSxNQUFNLG9DQUFvQyxDQUFDO0FBQy9ELE9BQU8sRUFBRSxVQUFVLEVBQUUsTUFBTSxxQ0FBcUMsQ0FBQztBQUVqRSxNQUFNLE9BQU8sT0FBTztJQUNsQixTQUFTO0lBQ0YsTUFBTSxDQUFDLEtBQUssQ0FBQyxnQkFBZ0I7UUFDbEMsTUFBTSxJQUFJLEdBQUcsT0FBTyxDQUFDLFlBQVksQ0FBQyxLQUFLLEVBQVcsQ0FBQztRQUNuRCxNQUFNLEdBQUcsR0FBRyxPQUFPLENBQUMsU0FBUyxDQUFDLEdBQUcsQ0FBQyxHQUFHLENBQUM7UUFDdEMsR0FBRyxDQUFDLGVBQWUsQ0FBQyxFQUFFLElBQUksRUFBRSxJQUFJLEVBQUUsT0FBTyxFQUFFLENBQUMsRUFBRSxFQUFFLEtBQUssRUFBRSxHQUFHLEVBQUUsT0FBTyxFQUFFLEVBQUU7WUFDckUsSUFBSSxHQUFHLEVBQUU7Z0JBQ1AsT0FBTyxDQUFDLEdBQUcsQ0FBQyxHQUFHLENBQUMsQ0FBQztnQkFDakIsTUFBTSxHQUFHLENBQUM7YUFDWDtZQUVELElBQUksQ0FBQyxPQUFPLENBQ1YsSUFBSSxPQUFPLENBQUM7Z0JBQ1YsVUFBVSxFQUFFLElBQUksVUFBVSxDQUFDLE9BQU8sQ0FBQyxVQUFVLENBQUM7Z0JBQzlDLFNBQVMsRUFBRSxJQUFJLFNBQVMsQ0FBQyxPQUFPLENBQUMsU0FBUyxDQUFDO2FBQzVDLENBQUMsQ0FDSCxDQUFDO1FBQ0osQ0FBQyxDQUFDLENBQUM7UUFDSCxPQUFPLElBQUksQ0FBQyxPQUFPLENBQUM7SUFDdEIsQ0FBQztJQU1ELFlBQVksVUFBNEQ7UUFDdEUsSUFBSSxDQUFDLFVBQVUsR0FBRyxVQUFVLENBQUMsVUFBVSxDQUFDO1FBQ3hDLElBQUksQ0FBQyxTQUFTLEdBQUcsVUFBVSxDQUFDLFNBQVMsQ0FBQztJQUN4QyxDQUFDO0NBQ0YifQ==
|
9
dist_ts/smartcrypto.classes.privatekey.d.ts
vendored
9
dist_ts/smartcrypto.classes.privatekey.d.ts
vendored
@ -1,9 +0,0 @@
|
||||
/// <reference types="node-forge" />
|
||||
import * as plugins from './smartcrypto.plugins.js';
|
||||
export declare class PrivateKey {
|
||||
static createFromPrivateKey(pemString: string): PrivateKey;
|
||||
static fromPemString(pemString: string): PrivateKey;
|
||||
forgePrivateKey: plugins.nodeForge.pki.PrivateKey;
|
||||
constructor(privateKeyArg: plugins.nodeForge.pki.PrivateKey);
|
||||
toPemString(): string;
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
import * as plugins from './smartcrypto.plugins.js';
|
||||
export class PrivateKey {
|
||||
// STATIC
|
||||
static createFromPrivateKey(pemString) {
|
||||
const privateKey = plugins.nodeForge.pki.privateKeyFromPem(pemString);
|
||||
return new PrivateKey(privateKey);
|
||||
}
|
||||
static fromPemString(pemString) {
|
||||
return new PrivateKey(plugins.nodeForge.pki.privateKeyFromPem(pemString));
|
||||
}
|
||||
constructor(privateKeyArg) {
|
||||
this.forgePrivateKey = privateKeyArg;
|
||||
}
|
||||
toPemString() {
|
||||
return plugins.nodeForge.pki.privateKeyToPem(this.forgePrivateKey);
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjcnlwdG8uY2xhc3Nlcy5wcml2YXRla2V5LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRjcnlwdG8uY2xhc3Nlcy5wcml2YXRla2V5LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxPQUFPLE1BQU0sMEJBQTBCLENBQUM7QUFFcEQsTUFBTSxPQUFPLFVBQVU7SUFDckIsU0FBUztJQUNGLE1BQU0sQ0FBQyxvQkFBb0IsQ0FBQyxTQUFpQjtRQUNsRCxNQUFNLFVBQVUsR0FBRyxPQUFPLENBQUMsU0FBUyxDQUFDLEdBQUcsQ0FBQyxpQkFBaUIsQ0FBQyxTQUFTLENBQUMsQ0FBQztRQUN0RSxPQUFPLElBQUksVUFBVSxDQUFDLFVBQVUsQ0FBQyxDQUFDO0lBQ3BDLENBQUM7SUFFTSxNQUFNLENBQUMsYUFBYSxDQUFDLFNBQWlCO1FBQzNDLE9BQU8sSUFBSSxVQUFVLENBQUMsT0FBTyxDQUFDLFNBQVMsQ0FBQyxHQUFHLENBQUMsaUJBQWlCLENBQUMsU0FBUyxDQUFDLENBQUMsQ0FBQztJQUM1RSxDQUFDO0lBS0QsWUFBWSxhQUErQztRQUN6RCxJQUFJLENBQUMsZUFBZSxHQUFHLGFBQWEsQ0FBQztJQUN2QyxDQUFDO0lBRU0sV0FBVztRQUNoQixPQUFPLE9BQU8sQ0FBQyxTQUFTLENBQUMsR0FBRyxDQUFDLGVBQWUsQ0FBQyxJQUFJLENBQUMsZUFBZSxDQUFDLENBQUM7SUFDckUsQ0FBQztDQUNGIn0=
|
9
dist_ts/smartcrypto.classes.publickey.d.ts
vendored
9
dist_ts/smartcrypto.classes.publickey.d.ts
vendored
@ -1,9 +0,0 @@
|
||||
/// <reference types="node-forge" />
|
||||
import * as plugins from './smartcrypto.plugins.js';
|
||||
export declare class PublicKey {
|
||||
static createFromPrivateKey(pemString: string): PublicKey;
|
||||
static fromPemString(pemString: string): PublicKey;
|
||||
forgePublicKey: plugins.nodeForge.pki.PublicKey;
|
||||
constructor(publicKeyArg: plugins.nodeForge.pki.PublicKey);
|
||||
toPemString(): string;
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
import * as plugins from './smartcrypto.plugins.js';
|
||||
export class PublicKey {
|
||||
// STATIC
|
||||
static createFromPrivateKey(pemString) {
|
||||
const privateKey = plugins.nodeForge.pki.publicKeyFromPem(pemString);
|
||||
return new PublicKey(privateKey);
|
||||
}
|
||||
static fromPemString(pemString) {
|
||||
return new PublicKey(plugins.nodeForge.pki.publicKeyFromPem(pemString));
|
||||
}
|
||||
constructor(publicKeyArg) {
|
||||
this.forgePublicKey = publicKeyArg;
|
||||
}
|
||||
toPemString() {
|
||||
return plugins.nodeForge.pki.publicKeyToPem(this.forgePublicKey);
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjcnlwdG8uY2xhc3Nlcy5wdWJsaWNrZXkuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGNyeXB0by5jbGFzc2VzLnB1YmxpY2tleS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssT0FBTyxNQUFNLDBCQUEwQixDQUFDO0FBRXBELE1BQU0sT0FBTyxTQUFTO0lBQ3BCLFNBQVM7SUFDRixNQUFNLENBQUMsb0JBQW9CLENBQUMsU0FBaUI7UUFDbEQsTUFBTSxVQUFVLEdBQUcsT0FBTyxDQUFDLFNBQVMsQ0FBQyxHQUFHLENBQUMsZ0JBQWdCLENBQUMsU0FBUyxDQUFDLENBQUM7UUFDckUsT0FBTyxJQUFJLFNBQVMsQ0FBQyxVQUFVLENBQUMsQ0FBQztJQUNuQyxDQUFDO0lBRU0sTUFBTSxDQUFDLGFBQWEsQ0FBQyxTQUFpQjtRQUMzQyxPQUFPLElBQUksU0FBUyxDQUFDLE9BQU8sQ0FBQyxTQUFTLENBQUMsR0FBRyxDQUFDLGdCQUFnQixDQUFDLFNBQVMsQ0FBQyxDQUFDLENBQUM7SUFDMUUsQ0FBQztJQUtELFlBQVksWUFBNkM7UUFDdkQsSUFBSSxDQUFDLGNBQWMsR0FBRyxZQUFZLENBQUM7SUFDckMsQ0FBQztJQUVNLFdBQVc7UUFDaEIsT0FBTyxPQUFPLENBQUMsU0FBUyxDQUFDLEdBQUcsQ0FBQyxjQUFjLENBQUMsSUFBSSxDQUFDLGNBQWMsQ0FBQyxDQUFDO0lBQ25FLENBQUM7Q0FDRiJ9
|
4
dist_ts/smartcrypto.classes.smartcrypto.d.ts
vendored
4
dist_ts/smartcrypto.classes.smartcrypto.d.ts
vendored
@ -1,4 +0,0 @@
|
||||
import { KeyPair } from './smartcrypto.classes.keypair.js';
|
||||
export declare class Smartcrypto {
|
||||
createKeyPair(): Promise<KeyPair>;
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
import * as plugins from './smartcrypto.plugins.js';
|
||||
import { KeyPair } from './smartcrypto.classes.keypair.js';
|
||||
export class Smartcrypto {
|
||||
async createKeyPair() {
|
||||
return KeyPair.createNewKeyPair();
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjcnlwdG8uY2xhc3Nlcy5zbWFydGNyeXB0by5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0Y3J5cHRvLmNsYXNzZXMuc21hcnRjcnlwdG8udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLE9BQU8sTUFBTSwwQkFBMEIsQ0FBQztBQUNwRCxPQUFPLEVBQUUsT0FBTyxFQUFFLE1BQU0sa0NBQWtDLENBQUM7QUFFM0QsTUFBTSxPQUFPLFdBQVc7SUFDZixLQUFLLENBQUMsYUFBYTtRQUN4QixPQUFPLE9BQU8sQ0FBQyxnQkFBZ0IsRUFBRSxDQUFDO0lBQ3BDLENBQUM7Q0FDRiJ9
|
4
dist_ts/smartcrypto.plugins.d.ts
vendored
4
dist_ts/smartcrypto.plugins.d.ts
vendored
@ -1,4 +0,0 @@
|
||||
import * as smartpromise from '@push.rocks/smartpromise';
|
||||
export { smartpromise };
|
||||
import nodeForge from 'node-forge';
|
||||
export { nodeForge };
|
@ -1,7 +0,0 @@
|
||||
// @pushrocks scope
|
||||
import * as smartpromise from '@push.rocks/smartpromise';
|
||||
export { smartpromise };
|
||||
// third party scope
|
||||
import nodeForge from 'node-forge';
|
||||
export { nodeForge };
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjcnlwdG8ucGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0Y3J5cHRvLnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsbUJBQW1CO0FBQ25CLE9BQU8sS0FBSyxZQUFZLE1BQU0sMEJBQTBCLENBQUM7QUFFekQsT0FBTyxFQUFFLFlBQVksRUFBRSxDQUFDO0FBRXhCLG9CQUFvQjtBQUNwQixPQUFPLFNBQVMsTUFBTSxZQUFZLENBQUM7QUFFbkMsT0FBTyxFQUFFLFNBQVMsRUFBRSxDQUFDIn0=
|
@ -2,17 +2,31 @@
|
||||
"gitzone": {
|
||||
"projectType": "npm",
|
||||
"module": {
|
||||
"githost": "gitlab.com",
|
||||
"githost": "code.foss.global",
|
||||
"gitscope": "push.rocks",
|
||||
"gitrepo": "smartcrypto",
|
||||
"description": "easy crypto methods",
|
||||
"description": "A library providing easy methods for cryptographic operations, including key pair generation.",
|
||||
"npmPackagename": "@push.rocks/smartcrypto",
|
||||
"license": "MIT",
|
||||
"projectDomain": "push.rocks"
|
||||
"projectDomain": "push.rocks",
|
||||
"keywords": [
|
||||
"cryptography",
|
||||
"encryption",
|
||||
"security",
|
||||
"public key",
|
||||
"private key",
|
||||
"RSA",
|
||||
"key pair generation",
|
||||
"node-forge",
|
||||
"typescript"
|
||||
]
|
||||
}
|
||||
},
|
||||
"npmci": {
|
||||
"npmGlobalTools": [],
|
||||
"npmAccessLevel": "public"
|
||||
},
|
||||
"tsdoc": {
|
||||
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**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.\n\n### Trademarks\n\nThis 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.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy 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.\n"
|
||||
}
|
||||
}
|
22
package.json
22
package.json
@ -1,8 +1,8 @@
|
||||
{
|
||||
"name": "@push.rocks/smartcrypto",
|
||||
"version": "2.0.3",
|
||||
"version": "2.0.5",
|
||||
"private": false,
|
||||
"description": "easy crypto methods",
|
||||
"description": "A library providing easy methods for cryptographic operations, including key pair generation.",
|
||||
"main": "dist_ts/index.js",
|
||||
"typings": "dist_ts/index.d.ts",
|
||||
"author": "Lossless GmbH",
|
||||
@ -39,5 +39,21 @@
|
||||
"browserslist": [
|
||||
"last 1 chrome versions"
|
||||
],
|
||||
"type": "module"
|
||||
"type": "module",
|
||||
"keywords": [
|
||||
"cryptography",
|
||||
"encryption",
|
||||
"security",
|
||||
"public key",
|
||||
"private key",
|
||||
"RSA",
|
||||
"key pair generation",
|
||||
"node-forge",
|
||||
"typescript"
|
||||
],
|
||||
"homepage": "https://code.foss.global/push.rocks/smartcrypto",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://code.foss.global/push.rocks/smartcrypto.git"
|
||||
}
|
||||
}
|
1
readme.hints.md
Normal file
1
readme.hints.md
Normal file
@ -0,0 +1 @@
|
||||
|
119
readme.md
119
readme.md
@ -1,39 +1,102 @@
|
||||
# @push.rocks/smartcrypto
|
||||
easy crypto methods
|
||||
|
||||
## Availabililty and Links
|
||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@push.rocks/smartcrypto)
|
||||
* [gitlab.com (source)](https://gitlab.com/push.rocks/smartcrypto)
|
||||
* [github.com (source mirror)](https://github.com/push.rocks/smartcrypto)
|
||||
* [docs (typedoc)](https://push.rocks.gitlab.io/smartcrypto/)
|
||||
|
||||
## Status for master
|
||||
|
||||
Status Category | Status Badge
|
||||
-- | --
|
||||
GitLab Pipelines | [](https://lossless.cloud)
|
||||
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
||||
npm | [](https://lossless.cloud)
|
||||
Snyk | [](https://lossless.cloud)
|
||||
TypeScript Support | [](https://lossless.cloud)
|
||||
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
Code Style | [](https://lossless.cloud)
|
||||
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
||||
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
||||
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
||||
## Install
|
||||
To install `@push.rocks/smartcrypto`, open a terminal and run the following command:
|
||||
```bash
|
||||
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.
|
||||
|
||||
## Contribution
|
||||
### 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:
|
||||
|
||||
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
|
||||
```typescript
|
||||
import { Smartcrypto } from '@push.rocks/smartcrypto';
|
||||
|
||||
## Contribution
|
||||
const smartCrypto = new Smartcrypto();
|
||||
```
|
||||
|
||||
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
|
||||
### Generating a Key Pair
|
||||
Generating a new RSA key pair is a common requirement. Let's see how `@push.rocks/smartcrypto` simplifies this process:
|
||||
|
||||
For further information read the linked docs at the top of this readme.
|
||||
```typescript
|
||||
(async () => {
|
||||
const keyPair = await smartCrypto.createKeyPair();
|
||||
console.log('Public Key:', keyPair.publicKey.toPemString());
|
||||
console.log('Private Key:', keyPair.privateKey.toPemString());
|
||||
})();
|
||||
```
|
||||
|
||||
## Legal
|
||||
> MIT licensed | **©** [Task Venture Capital GmbH](https://task.vc)
|
||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
||||
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:
|
||||
|
||||
```typescript
|
||||
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:
|
||||
|
||||
```typescript
|
||||
const privateKeyFromPem = PrivateKey.fromPemString(privateKeyPemString);
|
||||
```
|
||||
|
||||
The same methods apply to public keys with the `PublicKey` class:
|
||||
|
||||
```typescript
|
||||
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.
|
||||
|
||||
```typescript
|
||||
// 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](https://github.com/digitalbazaar/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.
|
||||
|
||||
## License and Legal Information
|
||||
|
||||
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](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.
|
||||
|
@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartcrypto',
|
||||
version: '2.0.3',
|
||||
version: '2.0.5',
|
||||
description: 'easy crypto methods'
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user