#89 OpenPGP.js sign cleartext

This commit is contained in:
the-djmaze 2022-02-02 16:50:27 +01:00
parent 66340614b5
commit f625abe0b2
3 changed files with 52 additions and 26 deletions

View file

@ -236,4 +236,21 @@ export const OpenPGPUserStore = new class {
}
}
async signCleartext(text, privateKey) {
const passphrase = prompt('OpenPGP.js Passphrase for ' + privateKey.id + ' ' + privateKey.emails[0]);
if (null !== passphrase) {
privateKey = await openpgp.decryptKey({
privateKey: privateKey.key,
passphrase
});
const unsignedMessage = await openpgp.createCleartextMessage({ text: text });
return await openpgp.sign({
message: unsignedMessage, // CleartextMessage or Message object
signingKeys: privateKey
// detached: false
});
}
return false;
}
};

View file

@ -106,17 +106,18 @@ export const PgpUserStore = new class {
* Returns the first library that can.
*/
async getKeyForSigning(email) {
/*
let key = GnuPGUserStore.getPrivateKeyFor(email, 1);
if (key) {
return ['gnupg', key];
}
key = OpenPGPUserStore.getPrivateKeyFor(email, 1);
*/
let key = OpenPGPUserStore.getPrivateKeyFor(email, 1);
if (key) {
return ['openpgp', key];
}
return await this.getMailvelopePrivateKeyFor(email, 1);
// return await this.getMailvelopePrivateKeyFor(email, 1);
}
async decrypt(message) {