1

SJCL 演示中,有一个复选框“将参数和经过身份验证的数据与消息一起发送”。将消息减少为非常短的字符串。

我找不到用于加密(和解密)函数的有效参数列表:

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

var decryptedMessage = sjcl.decrypt(key,encryptedMessage);
4

4 回答 4

2

如果输入密码,文本并单击加密,结果将在密文框中,例如:
密码:“pass”,消息:“text”,Authenticated data:“xxx”

结果:

{
"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
}

该网站的示例用法:

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

问题是,尽管可用性说明了模式CCMOCB2但通常不支持跨平台。

于 2016-06-02T21:26:48.860 回答
1

谢谢你的帮助!!!对于我的数据库中的最小消息开销,此解决方案适用于我:

  //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"
于 2016-06-04T18:31:23.630 回答
0

用这个:

<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>
于 2018-01-04T07:36:53.610 回答
-1

谢谢,史蒂芬。将选项分开可能会更简洁一些,因此我们可以遍历要删除的选项。此外,盐需要是 base64,我们可以使用 JavaScript 的 btoa() 函数轻松生成。

  //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"
于 2017-06-30T17:19:52.583 回答