Skip to content

Instantly share code, notes, and snippets.

@ivanoats
Created November 13, 2013 22:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivanoats/7458034 to your computer and use it in GitHub Desktop.
Save ivanoats/7458034 to your computer and use it in GitHub Desktop.
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<h1>Message Decoder</h1>
<button id="decrypt">Decrypt!</button>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/aes.js"></script>
<script>
var decoder = {
getPassword: function() {
this.password = prompt("Enter your password")
},
getCypherText: function() {
this.cypherText = document.URL.split('?')[1]
},
decrypt: function() {
this.getPassword()
this.getCypherText()
alert(CryptoJS.AES.decrypt(this.cypherText, this.password).toString(CryptoJS.enc.Utf8))
},
}
document.getElementById('decrypt').onclick = function() { decoder.decrypt() }
</script>
</body>
</html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<h1>Message Encoder</h1>
<p>This simple page lets you securely encrypt a message with a password. Your message will not leave your computer, and will not be sent over the Internet.</p>
<p>Once it's encoded, you'll be able to share your message with anyone else who has the password.</p>
<textarea id="message" rows="6" cols="60"></textarea>
<br>
<button id="encrypt" onclick="encoder.protect()">Lock Down</button>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/aes.js"></script>
<script>
var encoder = {
setMessage: function() {
this.message = document.getElementById('message').value
},
getPassword: function() {
this.password = prompt("Enter your password")
},
setUrl: function() {
this.url = document.URL + "decode.html?" + this.encrypt()
},
replaceMessageWithUrl: function () {
document.getElementById('message').value = this.url
},
encrypt: function() {
cypher = CryptoJS.AES.encrypt(this.message, this.password)
console.log("Verified: " +
CryptoJS.AES.decrypt(cypher, this.password).toString(CryptoJS.enc.Utf8))
return cypher
},
protect: function() {
console.log("protecting!");
this.setMessage()
this.getPassword()
this.setUrl()
this.replaceMessageWithUrl()
}
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment