update example

This commit is contained in:
Tankred Hase 2014-01-10 23:22:46 +01:00
parent c8ced71f5f
commit 73dc177a35
4 changed files with 16 additions and 20 deletions

View File

@ -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 %>'
}]
}
},

View File

@ -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

View File

@ -65,6 +65,7 @@ z8jl9UymAkoTcsVWRVr5PKR0zsCxaNV3w5hv6j12+US7mEWe2kuD
-----END PGP PUBLIC KEY BLOCK-----
</pre>
</div>
<script src="../dist/openpgp.min.js" type="text/javascript" charset="utf-8"></script>
<script src="./jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script src="./example.js" type="text/javascript" charset="utf-8"></script>
</body>

View File

@ -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);
}
});
}
}