From 73dc177a355a4050671e6f10f22428def5759a77 Mon Sep 17 00:00:00 2001 From: Tankred Hase Date: Fri, 10 Jan 2014 23:22:46 +0100 Subject: [PATCH] update example --- Gruntfile.js | 4 ++-- README.md | 7 ++++++- example/example.html | 1 + example/example.js | 24 +++++++----------------- 4 files changed, 16 insertions(+), 20 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 73541387..6eff3230 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -40,7 +40,7 @@ module.exports = function(grunt) { dest: ['dist/openpgp.js'], replacements: [{ from: /OpenPGP.js VERSION/g, - to: 'OpenPGP.js v<%= pkg.version %>.<%= grunt.template.today("yyyymmdd") %>' + to: 'OpenPGP.js v<%= pkg.version %>' }] }, openpgp_nodebug: { @@ -48,7 +48,7 @@ module.exports = function(grunt) { dest: ['dist/openpgp_nodebug.js'], replacements: [{ from: /OpenPGP.js VERSION/g, - to: 'OpenPGP.js v<%= pkg.version %>.<%= grunt.template.today("yyyymmdd") %>' + to: 'OpenPGP.js v<%= pkg.version %>' }] } }, diff --git a/README.md b/README.md index 7e2ae438..ff2949a5 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,12 @@ You can download a prebuilt minified version of the library under [releases](htt Then take `dist/openpgp.min.js` to use in your project. #Usage -It's best the check the documentation for detailed API information. There are also alot of useful examples under 'test/'. You can run the tests by calling: + // read public key + var pub_key = openpgp.key.readArmored($('#pubkey').text()); + // sign and encrypt message + var pgp_message = openpgp.encryptMessage(pub_key.keys, $('#message').val()); + +It's best to check the documentation for detailed API information. There are also alot of useful examples under 'test/'. You can run the tests by calling: npm install && npm test ## Documentation diff --git a/example/example.html b/example/example.html index 12d7f23e..e52e509f 100644 --- a/example/example.html +++ b/example/example.html @@ -65,6 +65,7 @@ z8jl9UymAkoTcsVWRVr5PKR0zsCxaNV3w5hv6j12+US7mEWe2kuD -----END PGP PUBLIC KEY BLOCK----- + diff --git a/example/example.js b/example/example.js index 828b3416..735d6294 100644 --- a/example/example.js +++ b/example/example.js @@ -1,8 +1,12 @@ function encrypt() { if (window.crypto.getRandomValues) { - require("./openpgp.min.js"); + + // read public key var pub_key = openpgp.key.readArmored($('#pubkey').text()); - $('#message').val(openpgp.encryptMessage(pub_key.keys,$('#message').val())); + // sign and encrypt message + var pgp_message = openpgp.encryptMessage(pub_key.keys, $('#message').val()); + + $('#message').val(pgp_message); window.alert("This message is going to be sent:\n" + $('#message').val()); return true; } else { @@ -10,18 +14,4 @@ function encrypt() { window.alert("Error: Browser not supported\nReason: We need a cryptographically secure PRNG to be implemented (i.e. the window.crypto method)\nSolution: Use Chrome >= 11, Safari >= 3.1 or Firefox >= 21"); return false; } -} - -function require(script) { - $.ajax({ - url: script, - dataType: "script", - async: false, // <-- this is the key - success: function () { - // all good... - }, - error: function () { - throw new Error("Could not load script " + script); - } - }); -} +} \ No newline at end of file