|
@@ -25,8 +25,8 @@ export class PgpKeyServerProvider {
|
|
|
|
|
|
public async publishPubKey(pubkey) {
|
|
public async publishPubKey(pubkey) {
|
|
console.log('passing pubkey to uplaoded : ', pubkey);
|
|
console.log('passing pubkey to uplaoded : ', pubkey);
|
|
- this.hkp.upload(pubkey).then(function() {
|
|
|
|
- console.log('public key successfully uploaded');
|
|
|
|
|
|
+ this.hkp.upload(pubkey).then(function(result) {
|
|
|
|
+ console.log('public key successfully uploaded',result);
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
@@ -35,11 +35,18 @@ export class PgpKeyServerProvider {
|
|
var options = {
|
|
var options = {
|
|
query: email
|
|
query: email
|
|
};
|
|
};
|
|
- let armoredPubkey = await this.hkp.lookup(options);
|
|
|
|
- let pubkey = (await openpgp.key.readArmored(armoredPubkey)).keys[0];
|
|
|
|
- console.log('Found latest public key:', pubkey);
|
|
|
|
- this.pk.push(pubkey);
|
|
|
|
- console.log('pk is:', this.pk);
|
|
|
|
|
|
+ try{
|
|
|
|
+ let armoredPubkey = await this.hkp.lookup(options);
|
|
|
|
+ let pubkey = (await openpgp.key.readArmored(armoredPubkey)).keys[0];
|
|
|
|
+ console.log('Found latest public key:', pubkey);
|
|
|
|
+ this.pk.push(pubkey);
|
|
|
|
+ return pubkey;
|
|
|
|
+ }
|
|
|
|
+ catch(err){
|
|
|
|
+ console.log("Error: key not found",err);
|
|
|
|
+ return "Key not found";
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -47,14 +54,16 @@ export class PgpKeyServerProvider {
|
|
* @param plainText plain text
|
|
* @param plainText plain text
|
|
* @param privateKey private key
|
|
* @param privateKey private key
|
|
*/
|
|
*/
|
|
- public async encrypt(plainText: string) {
|
|
|
|
|
|
+ public async encrypt(plainText) {
|
|
|
|
+ console.log('pk is:', this.pk);
|
|
|
|
+ if(!this.pk){ console.log("this.pk is empty"); return;}
|
|
// this.lookupKeys('rohit.shiva.gowda@gmail.com');
|
|
// this.lookupKeys('rohit.shiva.gowda@gmail.com');
|
|
const options = {
|
|
const options = {
|
|
message: openpgp.message.fromText(plainText), // input as Message object
|
|
message: openpgp.message.fromText(plainText), // input as Message object
|
|
publicKeys: await Promise.all(this.pk), // for encryption
|
|
publicKeys: await Promise.all(this.pk), // for encryption
|
|
// privateKey s: [privKeyObj] // for signing (optional)
|
|
// privateKey s: [privKeyObj] // for signing (optional)
|
|
}
|
|
}
|
|
- console.log('options are:', options);
|
|
|
|
|
|
+ // console.log('options are:', options);
|
|
const ciphertext = await openpgp.encrypt(options);
|
|
const ciphertext = await openpgp.encrypt(options);
|
|
console.log('encrypted text is:', ciphertext);
|
|
console.log('encrypted text is:', ciphertext);
|
|
return ciphertext.data;
|
|
return ciphertext.data;
|
|
@@ -64,15 +73,21 @@ export class PgpKeyServerProvider {
|
|
const privKeyObj = (await openpgp.key.readArmored(a)).keys[0];
|
|
const privKeyObj = (await openpgp.key.readArmored(a)).keys[0];
|
|
console.log('privKeyObj', privKeyObj);
|
|
console.log('privKeyObj', privKeyObj);
|
|
await privKeyObj.decrypt(this.passphrase);
|
|
await privKeyObj.decrypt(this.passphrase);
|
|
- console.log('a is:',a);
|
|
|
|
|
|
+ // console.log('a is:',a);
|
|
const options2 = {
|
|
const options2 = {
|
|
message: await openpgp.message.readArmored(encrypted), // parse armored message
|
|
message: await openpgp.message.readArmored(encrypted), // parse armored message
|
|
privateKeys: [privKeyObj] // for decryption
|
|
privateKeys: [privKeyObj] // 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!'
|
|
|
|
|
|
+ // console.log('options2 is: ', options2);
|
|
|
|
+ try{
|
|
|
|
+ let plaintext = await openpgp.decrypt(options2);
|
|
|
|
+ console.log('decrypted text is:', plaintext);
|
|
|
|
+ return plaintext.data // 'Hello, World!'
|
|
|
|
+ }
|
|
|
|
+ catch(err){
|
|
|
|
+ console.log('Error thrown:',err);
|
|
|
|
+ }
|
|
|
|
+ return null;
|
|
}
|
|
}
|
|
|
|
|
|
public async revokeKey() {
|
|
public async revokeKey() {
|