2

I'm pretty new to Angular. I'm trying to incorporate the openPGP library to my app (client side). I need some help on how to incorporate a javascript library to the Angular App. Thanks!

I'm reading through the openPGP docs https://github.com/openpgpjs/openpgpjs and the example provide in the docs is below:

var openpgp = require('openpgp');
var key = '-----BEGIN PGP PUBLIC KEY BLOCK ... END PGP PUBLIC KEY BLOCK-----';
var publicKey = openpgp.key.readArmored(key);
var pgpMessage = openpgp.encryptMessage(publicKey.keys, 'Hello, World!');

I prefer not to use require to source in openPGP to my app. So I've tried var openpgp = window.openpgp; which seems to not throw any error here. However, I get TypeError: Cannot read property 'key' of undefined error.

I should mention that I have installed openpgp using bower install.

I'm still trying to figure out what I can do to refer to openPGP in the Angular app. Thanks.

SamC
  • 71
  • 6
  • You might want to know, that StackOverflow Netiquette ( published as a recommended reading ) is not much tolerant to extremely broad questions. Some moderators even execute a [close] or [freeze] on such cases. **Try to narrow down the issue you have tried to solve, might be posta a <_code-snippet_> and mention what other things you have already tested, right?** – user3666197 Sep 16 '14 at 17:12
  • added more context to my question. thanks! :) – SamC Sep 16 '14 at 17:34

1 Answers1

2

If you're on the client-side, use a script tag, like

<script src="/path/to/openpgp.js"></script>

instead of require()

ki9
  • 5,183
  • 5
  • 37
  • 48