2

Using Sjcl i try to write a little service sending and receiving encrypted data from my javascript application.

Sadly, the sjcl documentation is lacking information on how to process their AES encrypted data. Their encrypt method returns an object containing serveral attributes of which i can only guess what is what.

{"iv":"i0t5BttfXwtY6hxuFSZxJg==",
"v":1,
"iter":1000,
"ks":128,
"ts":64,
"mode":"ccm",
"cipher":"aes",
"salt":"MZ8hpbz+5hU=",
"ct":"n5mR5jwawYwsaUV0xbcYXrcCXPWjR5qMG23qU5Spguz4jpjG5QdFMWSf"}

I can identify iter, ks, ts, mode, cipher and salt. My guess is that ct is the cipher text, representing the encrypted data. But what is v and iv?

I tried decrypting my cipher text giving ct as a parameter and even tried giving the whole result as a parameter but it always just produces errors:

var result = sjcl.json.encrypt(
  'pw123', 
  '{text: "this should be decrypted"}', 
  parameters, 
  rp
);

var originalText = sjcl.json.decrypt(
  'pw123', 
  result.ct,
  parameters,
  rp);

// Results in:
// Uncaught TypeError: Cannot read property 'replace' of undefined

How do i decrypt my ct using their decrypt method? Anyone any experience with this and can give a brief example?

4

2 回答 2

1

我的示例中的问题是我试图访问result.ct但结果是stringified JSON这样访问它的属性ct 显然返回undefined

在我的另一次尝试中,我通过传递parameters. 在不传递额外参数的情况下进行解密 -result字符串化 JSON 中已经给出的初始参数。

更新的小提琴在这里:http: //jsfiddle.net/e5rqogm3/1/

于 2015-03-26T13:40:57.380 回答
1

加密/解密使用默认参数:

var result = sjcl.json.encrypt(
  'pw123', 
  '{text: "this should be decrypted"}'
);

var originalText = sjcl.json.decrypt(
  'pw123', 
  result);

但什么是viv

v可能是密文的版本信息,以便以后版本的 SJCL 可以解密它。它被简单地设置为 1 并且从未在代码中使用。

iv是大多数分组密码模式(例如 CCM)所需的初始化向量。对于 AES,它是 16 字节长或只是块大小。

于 2015-02-06T12:14:57.047 回答