|
@@ -19,26 +19,23 @@ export class PgpKeyServerProvider {
|
|
};
|
|
};
|
|
|
|
|
|
let a = await openpgp.generateKey(options);
|
|
let a = await openpgp.generateKey(options);
|
|
- console.log('the key generated is:', a);
|
|
|
|
return a;
|
|
return a;
|
|
}
|
|
}
|
|
|
|
|
|
public async publishPubKey(pubkey) {
|
|
public async publishPubKey(pubkey) {
|
|
- console.log('passing pubkey to uplaoded : ', pubkey);
|
|
|
|
this.hkp.upload(pubkey).then(function(result) {
|
|
this.hkp.upload(pubkey).then(function(result) {
|
|
console.log('public key successfully uploaded',result);
|
|
console.log('public key successfully uploaded',result);
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
public async lookupKeys(email: string) {
|
|
public async lookupKeys(email: string) {
|
|
- console.log('looking up keys for',email);
|
|
|
|
|
|
+ // console.log('looking up keys for',email);
|
|
var options = {
|
|
var options = {
|
|
query: email
|
|
query: email
|
|
};
|
|
};
|
|
try{
|
|
try{
|
|
let armoredPubkey = await this.hkp.lookup(options);
|
|
let armoredPubkey = await this.hkp.lookup(options);
|
|
let pubkey = (await openpgp.key.readArmored(armoredPubkey)).keys[0];
|
|
let pubkey = (await openpgp.key.readArmored(armoredPubkey)).keys[0];
|
|
- console.log('Found latest public key:', pubkey);
|
|
|
|
this.pk.push(pubkey);
|
|
this.pk.push(pubkey);
|
|
return pubkey;
|
|
return pubkey;
|
|
}
|
|
}
|
|
@@ -55,33 +52,26 @@ export class PgpKeyServerProvider {
|
|
* @param privateKey private key
|
|
* @param privateKey private key
|
|
*/
|
|
*/
|
|
public async encrypt(plainText) {
|
|
public async encrypt(plainText) {
|
|
- console.log('pk is:', this.pk);
|
|
|
|
if(!this.pk){ console.log("this.pk is empty"); return;}
|
|
if(!this.pk){ console.log("this.pk is empty"); return;}
|
|
- // 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);
|
|
|
|
const ciphertext = await openpgp.encrypt(options);
|
|
const ciphertext = await openpgp.encrypt(options);
|
|
- console.log('encrypted text is:', ciphertext);
|
|
|
|
return ciphertext.data;
|
|
return ciphertext.data;
|
|
}
|
|
}
|
|
|
|
|
|
public async decrypt(encrypted: string,a) {
|
|
public async decrypt(encrypted: string,a) {
|
|
const privKeyObj = (await openpgp.key.readArmored(a)).keys[0];
|
|
const privKeyObj = (await openpgp.key.readArmored(a)).keys[0];
|
|
- console.log('privKeyObj', privKeyObj);
|
|
|
|
await privKeyObj.decrypt(this.passphrase);
|
|
await privKeyObj.decrypt(this.passphrase);
|
|
- // 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);
|
|
|
|
try{
|
|
try{
|
|
let plaintext = await openpgp.decrypt(options2);
|
|
let plaintext = await openpgp.decrypt(options2);
|
|
- console.log('decrypted text is:', plaintext);
|
|
|
|
return plaintext.data // 'Hello, World!'
|
|
return plaintext.data // 'Hello, World!'
|
|
}
|
|
}
|
|
catch(err){
|
|
catch(err){
|
|
@@ -94,7 +84,6 @@ export class PgpKeyServerProvider {
|
|
//using revocation certificate
|
|
//using revocation certificate
|
|
let pubkey = await this.storage.get("publicKey");
|
|
let pubkey = await this.storage.get("publicKey");
|
|
let atest = (await openpgp.key.readArmored(pubkey)).keys[0];
|
|
let atest = (await openpgp.key.readArmored(pubkey)).keys[0];
|
|
- console.log('inside revoke key pubkey is:', atest);
|
|
|
|
let revocatnCert = this.storage.get("revocationCert");
|
|
let revocatnCert = this.storage.get("revocationCert");
|
|
try {
|
|
try {
|
|
var options = {
|
|
var options = {
|