4 Commits

Author SHA1 Message Date
9e6cb240dd 1.0.5 2019-10-01 15:32:19 +02:00
03175e208a fix(core): update 2019-10-01 15:32:19 +02:00
2be99bdf48 1.0.4 2019-10-01 15:27:21 +02:00
0e21c84ab4 fix(core): update 2019-10-01 15:27:21 +02:00
7 changed files with 86 additions and 15 deletions

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartcrypto",
"version": "1.0.3",
"version": "1.0.5",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartcrypto",
"version": "1.0.3",
"version": "1.0.5",
"private": false,
"description": "easy crypto methods",
"main": "dist/index.js",

View File

@ -1 +1,4 @@
export * from './smartcrypto.classes.smartcrypto';
export * from './smartcrypto.classes.keypair';
export * from './smartcrypto.classes.privatekey';
export * from './smartcrypto.classes.publickey';

View File

@ -0,0 +1,36 @@
import * as plugins from './smartcrypto.plugins';
import { PublicKey } from './smartcrypto.classes.publickey';
import { PrivateKey } from './smartcrypto.classes.privatekey';
export class KeyPair {
// STATIC
public static async createNewKeyPair(): Promise<KeyPair> {
const done = plugins.smartpromise.defer<KeyPair>();
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;
}
// INSTANCE
public publicKey: PublicKey;
public privateKey: PrivateKey;
constructor(optionsArg: {
privateKey: PrivateKey;
publicKey: PublicKey;
}) {
this.privateKey = optionsArg.privateKey;
this.publicKey = optionsArg.publicKey;
}
}

View File

@ -0,0 +1,20 @@
import * as plugins from './smartcrypto.plugins';
export class PrivateKey {
// STATIC
public static createFromPrivateKey(pemString: string) {
const privateKey = plugins.nodeForge.pki.privateKeyFromPem(pemString);
return new PrivateKey(privateKey);
}
// INSTANCE
public forgePrivateKey: plugins.nodeForge.pki.PrivateKey;
constructor(privateKeyArg: plugins.nodeForge.pki.PrivateKey) {
this.forgePrivateKey = privateKeyArg;
}
public toPemString(): string {
return plugins.nodeForge.pki.privateKeyToPem(this.forgePrivateKey);
}
}

View File

@ -0,0 +1,21 @@
import * as plugins from './smartcrypto.plugins';
export class PublicKey {
// STATIC
public static createFromPrivateKey(pemString: string) {
const privateKey = plugins.nodeForge.pki.publicKeyFromPem(pemString);
return new PublicKey(privateKey);
}
// INSTANCE
public forgePublicKey: plugins.nodeForge.pki.PublicKey;
constructor (publicKeyArg: plugins.nodeForge.pki.PublicKey) {
this.forgePublicKey = publicKeyArg;
}
public toPemString(): string {
return plugins.nodeForge.pki.publicKeyToPem(this.forgePublicKey);
}
}

View File

@ -1,17 +1,8 @@
import * as plugins from './smartcrypto.plugins';
import { KeyPair } from './smartcrypto.classes.keypair';
export class Smartcrypto {
public static async createRSAKeyPair(): Promise<plugins.nodeForge.pki.KeyPair> {
const done = plugins.smartpromise.defer<plugins.nodeForge.pki.KeyPair>();
const rsa = plugins.nodeForge.pki.rsa;
rsa.generateKeyPair({bits: 2048, workers: 2}, (err, keypair) => {
if (err) {
console.log(err);
throw err;
}
done.resolve(keypair);
// keypair.privateKey, keypair.publicKey
});
return done.promise;
}
public async createKeyPair (): Promise<KeyPair> {
return KeyPair.createNewKeyPair();
};
}