2018-08-11 22:29:02 +00:00
|
|
|
import * as plugins from './smartacme.plugins';
|
|
|
|
const rsa = require('rsa-compat').RSA;
|
|
|
|
|
|
|
|
export class KeyPair {
|
2018-08-12 18:58:59 +00:00
|
|
|
rsaKeyPair: any;
|
2018-08-11 22:29:02 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* generates a fresh rsa keyPair
|
|
|
|
*/
|
|
|
|
static async generateFresh(): Promise<KeyPair> {
|
|
|
|
const done = plugins.smartpromise.defer();
|
|
|
|
var options = { bitlen: 2048, exp: 65537, public: true, pem: true, internal: true };
|
|
|
|
rsa.generateKeypair(options, function(err, keypair) {
|
2018-08-12 18:58:59 +00:00
|
|
|
if (err) {
|
2018-08-11 22:29:02 +00:00
|
|
|
console.log(err);
|
|
|
|
}
|
|
|
|
done.resolve(keypair);
|
|
|
|
});
|
|
|
|
const result: any = await done.promise;
|
|
|
|
const keyPair = new KeyPair(result);
|
|
|
|
return keyPair;
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor(rsaKeyPairArg) {
|
|
|
|
this.rsaKeyPair = rsaKeyPairArg;
|
|
|
|
}
|
|
|
|
}
|