I have a use case where I need to encrypt some text in the browser using javascript. Only the encrypted text will be stored on the server. The user should then be able to take the encrypted result and decrypt it with GPG on the command line. I want to use GPG as it's easily available and the AES appears to support iteration on passphrase hashing.

I'm hoping to use AES, however I don't understand what iteration count or salt GPG uses.

For example, http://cheeso.members.winisp.net/AES-Encryption.htm allows you to set parameters for AES decryption using Javascript:

Does anyone know what parameters to use to be compatible with GPG ?

  • 3
    $\begingroup$ Just a note: with your approach of encrypting at the client, your users still have to trust the server to send the right JavaScript, and not a version which gives the key to the server, too. (But they don't have to worry that someone will later force you to give out the keys, if you don't have them then.) $\endgroup$ Aug 31, 2011 at 13:38

2 Answers 2


GnuPG follows the OpenPGP format, which is a protocol in its own right -- it uses AES (among other algorithms) but is more complex than "just AES with the right parameters".

There is at least one OpenPGP implementation in Javascript (I have not tried it, though).

  • $\begingroup$ The OpenPGP implementation in Javascript seems to only support asymmetric encryption. $\endgroup$
    – Ian Purton
    Sep 1, 2011 at 11:10

The link in the question appears to be dead. So the question of parameters for that library might be irrelevant. But there are other options to achieve the end result of gpg symmetric encryption in JavaScript.

Another answer suggests Herbert Hanewinkel's JavaScript implementation of OpenPGP. That isn't going to work for symmetric encryption. But last year, I emailed Hanewinkel, to ask if I could use the library on my site. He said this:

that's ok, thank you for your mail. Future work on PGP in Javascript will be made by www.openpgpjs.org I am no longer working on this topic.


Herbert Hanewinkel

On the new project's website, there is a link to a github repo. This implementation does support symmetric ciphers.


So when you want to encrypt with javascript, use one of the symmetric ciphers in this library. And when you decrypt the message, run gpg from the command line with the option --symmetric

  • 1
    $\begingroup$ I'm sorry I don't see how this answers the question. The link is useful, but the rest of the post doesn't relate to the question (as far as I can see). Maybe it was intended as a comment? $\endgroup$
    – rath
    Sep 24, 2013 at 22:01
  • 2
    $\begingroup$ The other answer's suggestion is to Hanewinkel's library. This is why you should not use that library, and use this one instead. $\endgroup$
    – maxvgc
    Sep 25, 2013 at 20:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.