Created
November 23, 2014 08:35
-
-
Save thejefflarson/cbb8fc3d0834f7b33cde to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// WILL SAD TAB CHROME IF YOU OPEN THE INSPECTOR | |
// LOL CRYPTO | |
var c1 = document.querySelector("canvas#video"); | |
var c2 = document.querySelector("canvas#crypt"); | |
var video = document.querySelector("video"); | |
var plain = c1.getContext("2d"); | |
var crypt = c2.getContext("2d"); | |
var key; | |
var algo = "AES-CBC"; | |
var iv = new Uint8Array(16); | |
window.crypto.getRandomValues(iv); | |
var p = window.crypto.subtle.generateKey({name: "AES-CBC", length:128}, true, ['encrypt']); | |
p.then(function(val) { | |
var key = val; | |
navigator.webkitGetUserMedia({video:true}, function(stream){ | |
video.src = window.webkitURL.createObjectURL(stream); | |
video.play(); | |
function go(){ | |
plain.drawImage(video, 0, 0, 320, 240); | |
var img = plain.getImageData(0,0, 320, 240); | |
window.crypto.subtle.encrypt({name: "AES-CBC", iv: iv}, key, img.data).then(function(secret){ | |
crypt.putImageData(secret, 0 ,0); | |
}); | |
window.requestAnimationFrame(go); | |
}; | |
window.requestAnimationFrame(go); | |
}, function(err){ | |
console.log(err); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<style> | |
video, canvas { | |
width: 320px; | |
height: 240px; | |
} | |
video { | |
display:none; | |
} | |
</style> | |
</head> | |
<body> | |
<video></video> | |
<canvas width="320" height="240" id="video"></canvas> | |
<canvas width="320" height="240" id="crypt"></canvas> | |
<script src="cryptor.js"></script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment