How to use the openpgp.enums 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 DefinitelyTyped / DefinitelyTyped / types / openpgp / ts3.2 / openpgp-tests.ts View on Github external
openpgp.cleartext.readArmored("");

openpgp.crypto.crypto.generateSessionKey(openpgp.enums.symmetric.aes128);
openpgp.crypto.crypto.getPrefixRandom(openpgp.enums.symmetric.aes128);
// openpgp.crypto.crypto.getPrivateMpiCount(openpgp.enums.symmetric.aes128);
openpgp.crypto.crypto.publicKeyDecrypt(openpgp.enums.publicKey.rsa_encrypt, mpis, mpis, "");
openpgp.crypto.crypto.publicKeyEncrypt(openpgp.enums.publicKey.rsa_encrypt, mpis, mpi, "");

openpgp.crypto
// API update with no documentation
openpgp.crypto.cfb.decrypt("", "", "", true);
openpgp.crypto.cfb.encrypt("", "", "", true);
// Function removed from openpgp.crypto.cfb
// openpgp.crypto.cfb.mdc({}, "", "");

openpgp.crypto.hash.digest(openpgp.enums.hash.md5, new Uint8Array([0, 1]));
openpgp.crypto.hash.getHashByteLength(openpgp.enums.hash.md5);

openpgp.crypto.random.getRandomBN(mpi, mpi);
openpgp.crypto.random.getRandomBytes(0);
// function removed from openpgp.crypto.random
// openpgp.crypto.random.getRandomValues(openpgp.util.str_to_Uint8Array(""));
// openpgp.crypto.random.getSecureRandom(0, 1);

openpgp.crypto.signature.sign(openpgp.enums.publicKey.rsa_encrypt, openpgp.enums.hash.md5, mpis, new Uint8Array([0, 1]), new Uint8Array([0, 1]));
openpgp.crypto.signature.verify(openpgp.enums.publicKey.rsa_encrypt, openpgp.enums.hash.md5, mpis, mpis, new Uint8Array([0, 1]), new Uint8Array([0, 1]));

openpgp.key.generate(keyoptions);
openpgp.key.readArmored("");

openpgp.message.fromBinary(new Uint8Array([0x01, 0x02, 0x03]));
openpgp.message.fromText("");
github isomorphic-git / isomorphic-git / src / models / PGP.js View on Github external
static async createBinaryDetachedSignature (email, plaintext) {
    // Load keypair from localstorage
    const privateKey = PGP.lookupPrivateKey(email)
    if (privateKey) {
      // Is the only difference between cleartext signatures and detached binary the text normalization?
      // If so, I could probably add that functionality to openpgpjs - I'd just need a little guidance
      // on how to encode the PacketType and add the functionality to export to armor.js
      const bytes = openpgp.util.str2Uint8Array(plaintext)
      const message = openpgp.message.fromBinary(bytes)
      const signedMessage = message.sign([privateKey])
      const signature = signedMessage.packets.filterByTag(
        openpgp.enums.packet.signature
      )
      let armoredMessage = openpgp.armor.encode(
        openpgp.enums.armor.message,
        signature.write()
      )
      // Github won't recognize the signature unless we rename the headers (Tested 2017-01-04)
      armoredMessage = armoredMessage.replace(
        '-----BEGIN PGP MESSAGE-----\r\n',
        '-----BEGIN PGP SIGNATURE-----\r\n'
      )
      armoredMessage = armoredMessage.replace(
        '-----END PGP MESSAGE-----\r\n',
        '-----END PGP SIGNATURE-----\r\n'
      )
      return armoredMessage
    } else {
      throw new Error(
        'No PrivateKey in the OpenPGP keyring for the email address: ' + email
      )
github ProtonMail / WebClient / src / app / libraries / pmcrypto.js View on Github external
|| (info.sign.algorithm !== openpgp.enums.publicKey.rsa_encrypt_sign && info.sign.algorithm !== openpgp.enums.publicKey.rsa_sign)) {
            throw new Error('Key asymmetric algorithms must be RSA');
        }

        // Hash algorithms
        if (info.user.hash && info.user.hash.length) {
            if (info.user.hash[0] !== openpgp.enums.hash.sha256) {
                throw new Error('Preferred hash algorithm must be SHA256');
            }
        } else {
            throw new Error('Key missing preferred hash algorithms');
        }

        // Symmetric algorithms
        if (info.user.symmetric && info.user.symmetric.length) {
            if (info.user.symmetric[0] !== openpgp.enums.symmetric.aes256) {
                throw new Error('Preferred symmetric algorithm must be AES256');
            }
        } else {
            throw new Error('Key missing preferred symmetric algorithms');
        }

        // Compression algorithms
        if (info.user.compression && info.user.compression.length) {
            if (info.user.compression[0] !== openpgp.enums.compression.zlib) {
                throw new Error('Preferred compression algorithm must be zlib');
            }
        }

        return info;
    }
github isomorphic-git / isomorphic-git / src / models / PGP.js View on Github external
static async createBinaryDetachedSignature (email, plaintext) {
    // Load keypair from localstorage
    const privateKey = PGP.lookupPrivateKey(email)
    if (privateKey) {
      // Is the only difference between cleartext signatures and detached binary the text normalization?
      // If so, I could probably add that functionality to openpgpjs - I'd just need a little guidance
      // on how to encode the PacketType and add the functionality to export to armor.js
      const bytes = openpgp.util.str2Uint8Array(plaintext)
      const message = openpgp.message.fromBinary(bytes)
      const signedMessage = message.sign([privateKey])
      const signature = signedMessage.packets.filterByTag(
        openpgp.enums.packet.signature
      )
      let armoredMessage = openpgp.armor.encode(
        openpgp.enums.armor.message,
        signature.write()
      )
      // Github won't recognize the signature unless we rename the headers (Tested 2017-01-04)
      armoredMessage = armoredMessage.replace(
        '-----BEGIN PGP MESSAGE-----\r\n',
        '-----BEGIN PGP SIGNATURE-----\r\n'
      )
      armoredMessage = armoredMessage.replace(
        '-----END PGP MESSAGE-----\r\n',
        '-----END PGP SIGNATURE-----\r\n'
      )
      return armoredMessage
    } else {
github ProtonMail / WebClient / src / libraries / pmcrypto.js View on Github external
|| (info.sign.algorithm !== openpgp.enums.publicKey.rsa_encrypt_sign && info.sign.algorithm !== openpgp.enums.publicKey.rsa_sign)) {
            throw new Error('Key asymmetric algorithms must be RSA');
        }

        // Hash algorithms
        if (info.user.hash && info.user.hash.length) {
            if (info.user.hash[0] !== openpgp.enums.hash.sha256) {
                throw new Error('Preferred hash algorithm must be SHA256');
            }
        } else {
            throw new Error('Key missing preferred hash algorithms');
        }

        // Symmetric algorithms
        if (info.user.symmetric && info.user.symmetric.length) {
            if (info.user.symmetric[0] !== openpgp.enums.symmetric.aes256) {
                throw new Error('Preferred symmetric algorithm must be AES256');
            }
        } else {
            throw new Error('Key missing preferred symmetric algorithms');
        }

        // Compression algorithms
        if (info.user.compression && info.user.compression.length) {
            if (info.user.compression[0] !== openpgp.enums.compression.zlib) {
                throw new Error('Preferred compression algorithm must be zlib');
            }
        }

        return info;
    }
github openpgpjs / openpgpjs / resources / keyring.js View on Github external
this.getKeysForKeyId = function (keyId) {
    return checkForIdentityAndKeyTypeMatch(this.keys, idCheck, keyId, openpgp.enums.packet.public_key);
  };
github ProtonMail / WebClient / src / libraries / pmcrypto.js View on Github external
let msg;
            if (openpgp.message.Message.prototype.isPrototypeOf(encMessage)) {
                msg = encMessage;
            } else if (Uint8Array.prototype.isPrototypeOf(encMessage)) {
                msg = openpgp.message.read(encMessage);
            } else {
                msg = openpgp.message.readArmored(encMessage.trim());
            }

            const keyFilter = (packet) => {
                return packet.tag !== openpgp.enums.packet.symmetricallyEncrypted && packet.tag !== openpgp.enums.packet.symEncryptedIntegrityProtected;
            };

            const nonData = msg.packets.filter(keyFilter);
            const data = msg.packets.filterByTag(openpgp.enums.packet.symmetricallyEncrypted, openpgp.enums.packet.symEncryptedIntegrityProtected);

            if (nonData.length === 0) {
                return reject(new Error('No non-data packets found'));
            }
            if (data.length === 0) {
                return reject(new Error('No data packets found'));
            }

            resolve({
                keys: nonData.write(),
                data: data.write()
            });
        });
    }
github QTGate / QTGate-Desktop-Client / app / tools / initSystem.ts View on Github external
export const encryptMessage = ( openKeyOption, message: string, CallBack ) => {
	const option = {
		privateKeys: openKeyOption.privateKeys[0],
		publicKeys: openKeyOption.publicKeys,
		message: OpenPgp.message.fromText ( message ),
		compression: OpenPgp.enums.compression.zip
	}
	
	return OpenPgp.encrypt ( option ).then ( ciphertext => {
		
		return CallBack ( null, ciphertext.data )
	}).catch ( CallBack )
}
github breach / breach_core / lib / auto_updater.js View on Github external
keys.forEach(function(key) {
          if(key.verifyPrimaryKey() !== pgp.enums.keyStatus.valid) {
            return cb_(common.err('Failed to verify key '+
                                  key.primaryKey.fingerprint,
                                  'auto_updater:invalid_key'));
          }
          common.log.out('[auto_updater] Verified ' + 
                         key.primaryKey.fingerprint +
                         ' [' + key.users[0].userId.userid + ']');
        });