I have code that uses SJCL to encrypt and decrypt arrays of data. It encrypts fine, but when it decrypts, I always get the error, "ccm: tag doesn't match".
My code looks like this:
To encrypt:
var p = "{\"iv\":\"9Xz/lNqbuATWz+H3viOAQA\",\"v\":1,\"iter\":1000,\"ks\":128,\"ts\":64,\"mode\":\"ccm\",\"adata\":\"\",\"cipher\":\"aes\",\"salt\":\"ItnNFEoD4vc\"}";
var rp={};
var rawData = test.value[i][j];
rawData = rawData.toString();
var encrypted = sjcl.encrypt(password, rawData, p, rp);
encrypted = encrypted.match(/"ct":"([^"]*)"/)[1];
To decrypt:
var encodedData = test.value[i][j];
var coded = "{\"iv\":\"9Xz/lNqbuATWz+H3viOAQA\",\"v\":1,\"iter\":1000,\"ks\":128,\"ts\":64,\"mode\":\"ccm\",\"adata\":\"\",\"cipher\":\"aes\",\"salt\":\"ItnNFEoD4vc\",\"ct\":\"" + encodedData + "\"}"
var decrypted = sjcl.decrypt(password, coded);
Are the parameters passed in for the 3rd argument for sjcl.encrypt ignored?
The documentation header for encrypt states:
13 /** Simple encryption function.
14 * @param {String|bitArray} password The password or key.
15 * @param {String} plaintext The data to encrypt.
16 * @param {Object} [params] The parameters including tag, iv and salt.
17 * @param {Object} [rp] A returned version with filled-in parameters.
18 * @return {String} The ciphertext.
19 * @throws {sjcl.exception.invalid} if a parameter is invalid.
20 */
Based on that, I would expect it to use the parameters if they were passed in, but after debugging, it doesn't seem to be doing that.
The end result is I want to be able to deterministically encrypt and decrypt data between users.
thanks