1

In the SJCL Demo there is the checkbox "Send the parameters and authenticated data along with the message." to reduce the message to a very short string.

I can´t find a list with valid parameters for the use in the encrypt (and decrypt) function:

var encryptedMessage = sjcl.encrypt(key,message, ??? );

var decryptedMessage = sjcl.decrypt(key,encryptedMessage);
4
  • There are quite a lot of possible options: bitwiseshiftleft.github.io/sjcl/doc/symbols/src/… Commented Jun 2, 2016 at 20:36
  • When the checkbox is selected necessary parameters wil be sent along with the message such as the iv and password salt. If the receiver already knows these they don't need to be sent. Commented Jun 2, 2016 at 21:18
  • The options are listed here, which ones do you have trouble with? The encryption options are included in the "encryptedMessage" which is kind of a container format, so you don't need to specify them during decryption. Does that answer your question? Commented Jun 2, 2016 at 22:37
  • Note that this is kind of stupidity (not the first stupidity of SJCL) because it lets the attacker fill in the options, e.g a smaller authentication tag. You'd better check the variables yourself. Commented Jun 2, 2016 at 22:37

4 Answers 4

2

If you enter a password, text and click encrypt the result will be in the Ciphertext box, ex:
password:"pass", message:"text", Authenticated data:" xxx"

Result:

{
"iv":"tjp81jkAzUpW1bI9gLDDpg==", // iv Base64 encoded
"v":1,                           // version
"iter":1000,                     // iteration count
"ks":128,                        // key size in bits
"ts":64,                         // authentication strength
"mode":"ccm",                    // mode
"adata":"xxx",                   // authenticated data
"cipher":"aes",                  // cipher
"salt":"lx06UoJDNys=",           // key derivation salt
"ct":"Gv7ptKdTtUz6AGtX"          // ciphet text
}

Example usage from the site:

sjcl.encrypt("password", "data") 
sjcl.decrypt("password", "encrypted-data")

The catch is that notwithstanding the availability stated the modes CCM and OCB2 are not commonly supported across platforms.

Sign up to request clarification or add additional context in comments.

Comments

1

Thanks for your help!!! For a minimal message overhead in my database this solution works for me:

  //Encrypt
  var encryptedMessage = sjcl.encrypt("myPassword","myMessage",{mode:"ccm",iter:1000,ks:128,ts:64,v:1,cipher:"aes",adata:"",salt:"myGeneratedSalt"});
  var parsedMessage = JSON.parse(encryptedMessage);
  delete parsedMessage.mode;
  delete parsedMessage.iter;
  delete parsedMessage.ks;
  delete parsedMessage.ts;
  delete parsedMessage.v;
  delete parsedMessage.cipher;
  delete parsedMessage.salt;
  delete parsedMessage.adata;
  encryptedMessageWithoutParameters = JSON.stringify(parsedMessage);

  //Decrypt
  var parsedMessage = JSON.parse(encryptedMessageWithoutParameters);
  jQuery.extend(parsedMessage,{mode:"ccm",iter:1000,ks:128,ts:64,v:1,cipher:"aes",adata:"",salt:"myGeneratedSalt"});
  messageWithParameters = JSON.stringify(parsedMessage);
  var decryptedMessage = sjcl.decrypt("myPassword",messageWithParameters);

  //Result > "myMessage"

Comments

0

Use this:

<script type="text/javascript" src="js/sjcl.js"></script>
    <script type="text/javascript">

    var cypheredMsg = sjcl.encrypt("secret", "Hi Amresh!");
    var plainMsg = sjcl.decrypt("secret", cypheredMsg);

    console.log(cypheredMsg);
    console.log(plainMsg);

    </script>

Comments

-1

Thanks, Steffen. It might be a little cleaner to separate the options, so then we can iterate through the options to delete. Also, the salt needs to be base64, which we can easily generate with JavaScript's btoa() function.

  //Encrypt
  var salt = btoa( "myGeneratedSalt" );
  var options = {mode:"ccm",iter:1000,ks:128,ts:64,v:1,cipher:"aes",adata:"",salt:salt}
  var encryptedMessage = sjcl.encrypt("myPassword","myMessage",options);
  var parsedMessage = JSON.parse(encryptedMessage);
  var prop;
  for (prop in options) {
    delete parsedMessage[prop];
  }
  encryptedMessageWithoutParameters = JSON.stringify(parsedMessage);

  //Decrypt
  var parsedMessage = JSON.parse(encryptedMessageWithoutParameters);
  jQuery.extend(parsedMessage,options);
  messageWithParameters = JSON.stringify(parsedMessage);
  var decryptedMessage = sjcl.decrypt("myPassword",messageWithParameters);

  //Result > "myMessage"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.