Skip to content

Instantly share code, notes, and snippets.

@melastmohican
Created August 26, 2018 04:18
Show Gist options
  • Save melastmohican/45c3f2dc47b66f38c4c29bb7006c151f to your computer and use it in GitHub Desktop.
Save melastmohican/45c3f2dc47b66f38c4c29bb7006c151f to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/yaraya
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<script src='https://cdnjs.cloudflare.com/ajax/libs/sjcl/1.0.7/sjcl.js'></script>
</head>
<body>
<script id="jsbin-javascript">
// {\"iv\":\"n271PE9V4MNOIZnig5+aBA==\",\"v\":1,\"iter\":10000,\"ks\":128,\"ts\":64,\"mode\":\"gcm\",\"adata\":\"\",\"cipher\":\"aes\",\"salt\":\"kLME6vN+WdU/W9XVN9a1Z3E/p8HQ5C7X1La+3ZjEml1ytVRMfvtEXzeapbce2LjFI1dHEGtWv9bZ/U6K2CG1+K4lQPunFXWxXmsTQIXlGfwmpveg2AFeLFiqGmALnfbP\",\"ct\":\"DfTOGnKpU4k2AVWLWmUT3uemDjod\"}
var salt = btoa( "1234567890" );
var options = {mode:"gcm",iter:1000,ks:256,ts:128,v:1,cipher:"aes",iv: sjcl.random.randomWords(3, 0)};
//salt:salt}
console.log(options);
var encryptedMessage = sjcl.encrypt("pZlscguuUvDtTKUMhxQxdcXOrSV716QBHrOoiFAxgto=","{\"displayName\":\"displayname\",\"psid\":\"psid\",\"pageid\":\"pageid\",\"timestamp\":\"2018-08-23T05:20:22.330Z\"}",options);
var parsedMessage = JSON.parse(encryptedMessage);
console.log(parsedMessage);
console.log(parsedMessage.iv + parsedMessage.ct);
console.log(encodeURIComponent(parsedMessage.iv + parsedMessage.ct));
var decryptedMessage = sjcl.decrypt("pZlscguuUvDtTKUMhxQxdcXOrSV716QBHrOoiFAxgto=",encryptedMessage);
console.log(decryptedMessage);
</script>
<script id="jsbin-source-javascript" type="text/javascript">// {\"iv\":\"n271PE9V4MNOIZnig5+aBA==\",\"v\":1,\"iter\":10000,\"ks\":128,\"ts\":64,\"mode\":\"gcm\",\"adata\":\"\",\"cipher\":\"aes\",\"salt\":\"kLME6vN+WdU/W9XVN9a1Z3E/p8HQ5C7X1La+3ZjEml1ytVRMfvtEXzeapbce2LjFI1dHEGtWv9bZ/U6K2CG1+K4lQPunFXWxXmsTQIXlGfwmpveg2AFeLFiqGmALnfbP\",\"ct\":\"DfTOGnKpU4k2AVWLWmUT3uemDjod\"}
var salt = btoa( "1234567890" );
var options = {mode:"gcm",iter:1000,ks:256,ts:128,v:1,cipher:"aes",iv: sjcl.random.randomWords(3, 0)};
//salt:salt}
console.log(options);
var encryptedMessage = sjcl.encrypt("pZlscguuUvDtTKUMhxQxdcXOrSV716QBHrOoiFAxgto=","{\"displayName\":\"displayname\",\"psid\":\"psid\",\"pageid\":\"pageid\",\"timestamp\":\"2018-08-23T05:20:22.330Z\"}",options);
var parsedMessage = JSON.parse(encryptedMessage);
console.log(parsedMessage);
console.log(parsedMessage.iv + parsedMessage.ct);
console.log(encodeURIComponent(parsedMessage.iv + parsedMessage.ct));
var decryptedMessage = sjcl.decrypt("pZlscguuUvDtTKUMhxQxdcXOrSV716QBHrOoiFAxgto=",encryptedMessage);
console.log(decryptedMessage);
</script></body>
</html>
// {\"iv\":\"n271PE9V4MNOIZnig5+aBA==\",\"v\":1,\"iter\":10000,\"ks\":128,\"ts\":64,\"mode\":\"gcm\",\"adata\":\"\",\"cipher\":\"aes\",\"salt\":\"kLME6vN+WdU/W9XVN9a1Z3E/p8HQ5C7X1La+3ZjEml1ytVRMfvtEXzeapbce2LjFI1dHEGtWv9bZ/U6K2CG1+K4lQPunFXWxXmsTQIXlGfwmpveg2AFeLFiqGmALnfbP\",\"ct\":\"DfTOGnKpU4k2AVWLWmUT3uemDjod\"}
var salt = btoa( "1234567890" );
var options = {mode:"gcm",iter:1000,ks:256,ts:128,v:1,cipher:"aes",iv: sjcl.random.randomWords(3, 0)};
//salt:salt}
console.log(options);
var encryptedMessage = sjcl.encrypt("pZlscguuUvDtTKUMhxQxdcXOrSV716QBHrOoiFAxgto=","{\"displayName\":\"displayname\",\"psid\":\"psid\",\"pageid\":\"pageid\",\"timestamp\":\"2018-08-23T05:20:22.330Z\"}",options);
var parsedMessage = JSON.parse(encryptedMessage);
console.log(parsedMessage);
console.log(parsedMessage.iv + parsedMessage.ct);
console.log(encodeURIComponent(parsedMessage.iv + parsedMessage.ct));
var decryptedMessage = sjcl.decrypt("pZlscguuUvDtTKUMhxQxdcXOrSV716QBHrOoiFAxgto=",encryptedMessage);
console.log(decryptedMessage);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment