diff --git a/index.js b/index.js index 96a805f..9eb25e0 100644 --- a/index.js +++ b/index.js @@ -1,18 +1,13 @@ const openpgp = require('openpgp') -const toBinary = (data) => { - data = openpgp.util.encode_utf8(data) - data = openpgp.util.str_to_Uint8Array(data) - return data -} - module.exports.pgp = { async sign ({ payload, secretKey }) { // We need to use fromBinary because fromText screws with line endings - const data = toBinary(payload) //openpgp.util.encode_utf8(payload) + const data = openpgp.util.encode_utf8(payload) + const message = openpgp.message.fromBinary(data) const privateKeys = (await openpgp.key.readArmored(secretKey)).keys let { signature } = await openpgp.sign({ - data, + message, privateKeys, detached: true, armor: true @@ -20,7 +15,7 @@ module.exports.pgp = { return { signature } }, async verify ({ payload, publicKey, signature }) { - const data = toBinary(payload) + const data = openpgp.util.encode_utf8(payload) const message = openpgp.message.fromBinary(data) signature = await openpgp.signature.readArmored(signature) const publicKeys = (await openpgp.key.readArmored(publicKey)).keys