Skip to content

Instantly share code, notes, and snippets.

@declank
Last active August 29, 2015 14:12
Show Gist options
  • Save declank/689b972dbcbfd3ccc12c to your computer and use it in GitHub Desktop.
Save declank/689b972dbcbfd3ccc12c to your computer and use it in GitHub Desktop.

Revisions

  1. declank revised this gist Dec 23, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion sjcl.html
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,7 @@ <h1>Demo of <a href="http://bitwiseshiftleft.github.io/sjcl/" target="_blank">St
    <input type="text" id="message" value="The quick brown fox jumps over the lazy dog"><br>
    <button id="encrypt">Encrypt</button><br>
    <output id="output"></output>
    <script src="http://cdnjs.cloudflare.com/ajax/libs/sjcl/1.0.0/sjcl.min.js"></script>
    <script src="//cdnjs.cloudflare.com/ajax/libs/sjcl/1.0.0/sjcl.min.js"></script>
    <script>

    var encryptButton = document.getElementById("encrypt");
  2. declank created this gist Dec 23, 2014.
    39 changes: 39 additions & 0 deletions sjcl.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    </head>
    <body>
    <h1>Demo of <a href="http://bitwiseshiftleft.github.io/sjcl/" target="_blank">Stanford Javascript Crypto Library</a></h1>
    <p>Generates HMAC using SHA-256</p>
    <input type="text" id="key" value="key"><br>
    <input type="text" id="message" value="The quick brown fox jumps over the lazy dog"><br>
    <button id="encrypt">Encrypt</button><br>
    <output id="output"></output>
    <script src="http://cdnjs.cloudflare.com/ajax/libs/sjcl/1.0.0/sjcl.min.js"></script>
    <script>

    var encryptButton = document.getElementById("encrypt");
    encryptButton.addEventListener('click', function(event) {
    'use strict';
    if(typeof sjcl === 'undefined') {
    alert("Please wait for library to load...");
    } else {
    var key = document.getElementById("key").value;
    var message = document.getElementById('message').value;
    var hmac = new sjcl.misc.hmac(sjcl.codec.utf8String.toBits(key));

    var output = "";

    output += "Key: " + key + "<br>";
    output += "Message: " + message + '<br>';
    output += "HMAC: 0x" + sjcl.codec.hex.fromBits(hmac.encrypt(message)) + '<br>';

    document.getElementById('output').innerHTML = output;
    }
    });


    </script>
    </body>
    </html>