How to use the openpgp.message function in openpgp

To help you get started, we’ve selected a few openpgp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github airswap / AirSwap.js / src / keySpace / index.js View on Github external
return new Promise(async (resolve, reject) => {
      openpgp
        .decrypt({
          message: await openpgp.message.readArmored(encryptedMessage),
          publicKeys: (await openpgp.key.readArmored(publicKeyArmored)).keys, // for verification (optional)
          privateKeys: [privKeyObj],
        })
        .then(plaintext => {
          resolve(plaintext.data)
        })
        .catch(reject)
    })
  }
github DefinitelyTyped / DefinitelyTyped / types / openpgp / ts3.2 / openpgp-tests.ts View on Github external
.then(function (publicKey) {
        return {
            message: openpgp.message.fromText('Hello, World!'),
            publicKeys: publicKey.keys
        };
    })
    .then(openpgp.encrypt)
github QTGate / QTGate-Desktop-Client / app / encrypt.ts View on Github external
export const deCryptoWithKey1 = ( data: string, publicKey: string, privateKey: string, password: string, CallBack ) => {
	let _return = false
	const options: any = {
		message: openpgp.message.readArmored ( data ),
		publicKeys: openpgp.key.readArmored ( publicKey ).keys,
		privateKey: openpgp.key.readArmored ( privateKey ).keys[0]
	}
	if ( ! options.privateKey.decrypt ( password )) {
		return CallBack ( new Error ('saveImapData key password error!' ))
	}
	openpgp.decrypt ( options ).then ( plaintext => {
		_return = true
		return CallBack ( null, plaintext.data )
	}).catch ( err => {
		console.log ( data )
		console.log ( err )
		if ( !_return ) {
			return CallBack ( err )
		}
github NEEOInc / neeo-sdk / src / lib / expressBrainDriver / crypto / index.ts View on Github external
function decrypt(cipher: string): Promise {
  if (isEmpty(cipher)) {
    debug('empty cipher!');
    return Promise.reject(new Error('EMPTY_CIPHER'));
  }
  if (!privateKey) {
    return Promise.reject(new Error('NO_KEYS'));
  }
  let message: openpgp.message.Message;
  try {
    message = openpgp.message.readArmored(cipher);
  } catch (err) {
    debug('READ_ARMORED_FAILED', err.message);
    return Promise.reject(err);
  }
  return openpgp.decrypt({ privateKey, message })
    .then(({ data }) => data as string);
}
github RedpointGames / pkgsign / src / lib / identity / pgp.ts View on Github external
const attemptVerify = async (rawPublicKeys: string) => {
      try {
        const publicKeys = (await openpgp.key.readArmored(rawPublicKeys)).keys;
        const verifyOptions = {
          message: openpgp.message.fromText(deterministicString),
          signature: await openpgp.signature.readArmored(signature),
          publicKeys: publicKeys
        };
        const verifiedMessage = await openpgp.verify(verifyOptions);
        return verifiedMessage.signatures.length >= 1;
      } catch (e) {
        return false;
      }
    };
github RedpointGames / pkgsign / src / lib / identity / keybase.ts View on Github external
const attemptVerify = async (rawPublicKeys: string) => {
      try {
        const publicKeys = (await openpgp.key.readArmored(rawPublicKeys)).keys;
        const verifyOptions = {
          message: openpgp.message.fromText(deterministicString),
          signature: await openpgp.signature.readArmored(signature),
          publicKeys: publicKeys
        };
        const verifiedMessage = await openpgp.verify(verifyOptions);
        return verifiedMessage.signatures.length >= 1;
      } catch (e) {
        return false;
      }
    };
github kenforthewin / mentat / assets / js / actions / cryptoActions.js View on Github external
privKeyObj.decrypt(state.cryptoReducer.passphrase).then(() => {
      const options = {
        message: openpgp.message.readArmored(encryptedPrivateKey),
        privateKeys: [privKeyObj]
      };
      openpgp.decrypt(options).then((plaintext) => {
        dispatch({
          type: 'new_group_key',
          privateKey: plaintext.data,
          publicKey,
          room,
          name
        });
        const groupPrivateKey = openpgp.key.readArmored(plaintext.data).keys[0];
        users.forEach((user) => {
          if (user.avatar) {
            const groupOptions = {
              privateKeys: [groupPrivateKey],
              message: openpgp.message.readArmored(user.avatar)
github kenforthewin / mentat / assets / js / actions / cryptoActions.js View on Github external
return async (dispatch, getState) => {
    const state = getState();
    var privKeyObj = openpgp.key.readArmored(state.cryptoReducer.privateKey).keys[0];
    await privKeyObj.decrypt(state.cryptoReducer.passphrase)
    const privateKeyOptions = {
      message: openpgp.message.readArmored(encryptedPrivateKey),
      privateKeys: [privKeyObj]
    };
    const privateKey = await openpgp.decrypt(privateKeyOptions)
    const passphraseOptions = {
      message: openpgp.message.readArmored(encryptedPassphrase),
      privateKeys: [privKeyObj]
    };
    const passphrase = await openpgp.decrypt(passphraseOptions)
    const newPrivateKey = privateKey.data
    const newPassphrase = passphrase.data
    dispatch({
      type: 'new_key',
      publicKey,
      privateKey: newPrivateKey,
      passphrase: newPassphrase
    })
    privKeyObj = openpgp.key.readArmored(newPrivateKey).keys[0];
    await privKeyObj.decrypt(newPassphrase)
    requests.requests.forEach(async (request) => {
      const privateGroupKeyOptions = {
        message: openpgp.message.readArmored(request.encrypted_team_private_key),
github scastiel / protonmail-export / src / ConversationFetcher.js View on Github external
async decryptMessageBody(message: any): Promise {
        try {
            const messageBody = await openpgp.decrypt({
                message: openpgp.message.readArmored(message.Body),
                privateKey: this._privateKey
            });
            message.BodyDecrypted = messageBody.data;
        } catch (err) {}
        return message;
    }
}
github henryboldi / felony / app / utils / pgp.js View on Github external
export async function decrypt(encryptedMessage, privateKeyArmored) {
  const encryptedMessageMassaged = massagePGP(encryptedMessage)
  const privateKey = openpgp.key.readArmored(privateKeyArmored).keys[0]
  const passphrase = getPrivateKeyPassphrase(privateKey)

  privateKey.decrypt(passphrase)

  const options = {
    message: openpgp.message.readArmored(encryptedMessageMassaged),
    privateKey,
  }
  const plaintext = await openpgp.decrypt(options)

  return plaintext.data
}