|
@@ -35,6 +35,7 @@ export class WriteTweetPage {
|
|
|
openpgp;
|
|
|
privateKey;
|
|
|
publicKey;
|
|
|
+ pk: any[]=[];
|
|
|
passp = 'super long and hard to guess secret' ;
|
|
|
|
|
|
|
|
@@ -59,43 +60,89 @@ export class WriteTweetPage {
|
|
|
});
|
|
|
|
|
|
this.addValidators();
|
|
|
-
|
|
|
- this.generateKeys();
|
|
|
+ this.encryptDecryptFunction();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
public async encryptDecryptFunction () {
|
|
|
- // await openpgp.initWorker({});
|
|
|
- // await this.generateKeys();
|
|
|
- console.log('priv key: ',this.privateKey,'this . pubkey',this.publicKey);
|
|
|
+ await openpgp.initWorker({path:'assets/scripts/openpgp.worker.js'});
|
|
|
+ let a = await this.generateKeys();
|
|
|
+ console.log('a is:',a.publicKeyArmored);
|
|
|
+ let b = await this.generateKeys();
|
|
|
+ console.log('b is:',b.publicKeyArmored);
|
|
|
+ let c = await this.generateKeys();
|
|
|
+ this.privateKey =c.privateKeyArmored;
|
|
|
+ this.publicKey = c.publicKeyArmored;
|
|
|
+
|
|
|
+ this.pk.push(a.publicKeyArmored);
|
|
|
+ this.pk.push(b.publicKeyArmored);
|
|
|
+// this.pk = [`----BEGIN PGP PUBLIC KEY BLOCK-----
|
|
|
+// Version: OpenPGP.js v4.7.1
|
|
|
+// Comment: https://openpgpjs.org
|
|
|
+
|
|
|
+// xjMEXfAn1xYJKwYBBAHaRw8BAQdAAMVNOABw8MBtrtYR8KC3tSro3wITyApT
|
|
|
+// TVjKVCppD+DNG0pvbiBTbWl0aCA8am9uQGV4YW1wbGUuY29tPsJ3BBAWCgAf
|
|
|
+// BQJd8CfXBgsJBwgDAgQVCAoCAxYCAQIZAQIbAwIeAQAKCRD+efBRXzuMsfA7
|
|
|
+// AQCEgoToFzv2hT9BREdiQp531/AHSyoZWmWvSZSvmga40gD8C+zwbCySnkhQ
|
|
|
+// pb4L0DCKtSDa7pLg2g0OcxJlbSZWHQ3OOARd8CfXEgorBgEEAZdVAQUBAQdA
|
|
|
+// p4mVY17dPWf6VCBqW10Ybk5JgUO6FK0OsETWw3gG2zcDAQgHwmEEGBYIAAkF
|
|
|
+// Al3wJ9cCGwwACgkQ/nnwUV87jLFHbAD9GyoL7dcTDGQoqtrhKozdgnzfugTb
|
|
|
+// er0bwU15WNMjefkA/jEqK9YUNcRrFKIuac9PVibGgutL8ak7ukysw6iTcCsM
|
|
|
+// =fmhE
|
|
|
+// -----END PGP PUBLIC KEY BLOCK-----`,
|
|
|
+// `-----BEGIN PGP PUBLIC KEY BLOCK-----
|
|
|
+// Version: OpenPGP.js v4.7.1
|
|
|
+// Comment: https://openpgpjs.org
|
|
|
+
|
|
|
+// xjMEXfAn1hYJKwYBBAHaRw8BAQdAsF1ivpd0HU8ogj02LDv6BTOxNMWGZaEc
|
|
|
+// OyZBwqoYJPrNG0pvbiBTbWl0aCA8am9uQGV4YW1wbGUuY29tPsJ3BBAWCgAf
|
|
|
+// BQJd8CfWBgsJBwgDAgQVCAoCAxYCAQIZAQIbAwIeAQAKCRDEruv77flRJ32B
|
|
|
+// AP93GIBcUW2okROoZZhdPVeqjRD72Ft64imXpdZ0jx4ohgEA5Kv9vs2kV73q
|
|
|
+// k6fcdf7qD/i5gMExU0+vV05c9VxBYwfOOARd8CfWEgorBgEEAZdVAQUBAQdA
|
|
|
+// 1J7E03ZopUnsIeNzeiZvba6qxhhUbpmBZ1aN1HhWUlEDAQgHwmEEGBYIAAkF
|
|
|
+// Al3wJ9YCGwwACgkQxK7r++35USdTqQD/ZEg8X5tMx75nQe4mGlyiRjmmtWLw
|
|
|
+// n9bslTdjBIszs/EA/R1WIm6ji4Ru1dJWc3ISisz78xTM2H8U7fnP8yjFcWcD
|
|
|
+// =hgnW
|
|
|
+// -----END PGP PUBLIC KEY BLOCK-----`];
|
|
|
+ console.log('array of pub keys is :',this.pk);
|
|
|
+ this.pk = this.pk.map(async (key) => {
|
|
|
+ return (await openpgp.key.readArmored(key)).keys[0]
|
|
|
+ });
|
|
|
+
|
|
|
+ console.log('priv key: ',this.privateKey,'this.pubkey',this.pk);
|
|
|
let encrypted;
|
|
|
const privKeyObj = (await openpgp.key.readArmored(this.privateKey)).keys[0];
|
|
|
console.log('privKeyObj',privKeyObj);
|
|
|
- await privKeyObj.decrypt(this.passp)
|
|
|
+ const bla = await privKeyObj.decrypt(this.passp);
|
|
|
+
|
|
|
+ // const options = {
|
|
|
+ // message: openpgp.message.fromText('Hello, World!'), // input as Message object
|
|
|
+ // publicKeys: (await openpgp.key.readArmored(this.publicKey)).keys, // for encryption
|
|
|
+ // privateKeys: [privKeyObj] // for signing (optional)
|
|
|
+ // }
|
|
|
|
|
|
const options = {
|
|
|
message: openpgp.message.fromText('Hello, World!'), // input as Message object
|
|
|
- publicKeys: (await openpgp.key.readArmored(this.publicKey)).keys, // for encryption
|
|
|
+ publicKeys: await Promise.all(this.pk), // for encryption
|
|
|
privateKeys: [privKeyObj] // for signing (optional)
|
|
|
}
|
|
|
|
|
|
- openpgp.encrypt(options).then(ciphertext => {
|
|
|
- encrypted = ciphertext.data // '-----BEGIN PGP MESSAGE ... END PGP MESSAGE-----'
|
|
|
- console.log('encrypted text is:',encrypted);
|
|
|
- return encrypted
|
|
|
- })
|
|
|
- .then(async encrypted => {
|
|
|
- const options = {
|
|
|
- message: await openpgp.message.readArmored(encrypted), // parse armored message
|
|
|
- publicKeys: (await openpgp.key.readArmored(this.publicKey)).keys, // for verification (optional)
|
|
|
- privateKeys: [privKeyObj] // for decryption
|
|
|
- }
|
|
|
-
|
|
|
- openpgp.decrypt(options).then(plaintext => {
|
|
|
- console.log('decrypted text is:',plaintext,plaintext.data);
|
|
|
- return plaintext.data // 'Hello, World!'
|
|
|
- })
|
|
|
-
|
|
|
- })
|
|
|
+ const ciphertext = await openpgp.encrypt(options);
|
|
|
+ encrypted = ciphertext.data; // '-----BEGIN PGP MESSAGE ... END PGP MESSAGE-----'
|
|
|
+ console.log('encrypted is:',encrypted);
|
|
|
+
|
|
|
+ let aprivKeyObj = (await openpgp.key.readArmored(a.privateKeyArmored)).keys[0];
|
|
|
+ await aprivKeyObj.decrypt(this.passp);
|
|
|
+
|
|
|
+ const options2 = {
|
|
|
+ message: await openpgp.message.readArmored(encrypted), // parse armored message
|
|
|
+ privateKeys: [aprivKeyObj] // for decryption
|
|
|
+ }
|
|
|
+ console.log('options2 is: ',options2);
|
|
|
+ let plaintext = await openpgp.decrypt(options2);
|
|
|
+ console.log('decrypted text is:',plaintext,plaintext.data);
|
|
|
+ return plaintext.data // 'Hello, World!'
|
|
|
+
|
|
|
}
|
|
|
|
|
|
public async generateKeys(){
|
|
@@ -105,23 +152,12 @@ export class WriteTweetPage {
|
|
|
passphrase: this.passp // protects the private key
|
|
|
};
|
|
|
|
|
|
- // var vm = this;
|
|
|
- // openpgp.generateKey(options)
|
|
|
- // .then(function(vm,key) {
|
|
|
- // if(key){
|
|
|
- // var privkey = key.privateKeyArmored; // '-----BEGIN PGP PRIVATE KEY BLOCK ... '
|
|
|
- // var pubkey = key.publicKeyArmored; // '-----BEGIN PGP PUBLIC KEY BLOCK ... '
|
|
|
- // var revocationCertificate = key.revocationCertificate; // '-----BEGIN PGP PUBLIC KEY BLOCK ... '
|
|
|
- // vm.privateKey =privkey;
|
|
|
- // vm.publicKey = pubkey;
|
|
|
- // }
|
|
|
- // })
|
|
|
-
|
|
|
- const a = await openpgp.generateKey(options);
|
|
|
- console.log('resolved a = ',a);
|
|
|
- this.privateKey =a.privateKeyArmored;
|
|
|
- this.publicKey = a.publicKeyArmored;
|
|
|
- this.encryptDecryptFunction();
|
|
|
+ let a = await openpgp.generateKey(options);
|
|
|
+ return a;
|
|
|
+ // console.log('resolved a = ',a);
|
|
|
+ // this.privateKey =a.privateKeyArmored;
|
|
|
+ // this.publicKey = a.publicKeyArmored;
|
|
|
+ // this.encryptDecryptFunction();
|
|
|
}
|
|
|
|
|
|
|