Does SJCL content need to be json_encode(d) when it is read from a database?

306 views Asked by At

Overview

I am attempting to encrypt data, send it to a database, then decrypt the data using the Stanford Javascript Crypto Library (SJCL).

Problem

Whenever I attempt to call the data from the database, I get a "CORRUPT: ccm: tag doesn't match" error. I have looked this up and it seems as if my content or password is corrupted, and because the password is being straight from a textbox, I have narrowed it down to the content.

Code Snippet

(PHP)

$paste = $_GET['url'];
$query = "SELECT * FROM posts WHERE url='$paste'";
$result = mysqli_query($db, $query);
$row = mysqli_fetch_array($result);
$t = $row['title'];
$c = $row['content'];
$con = json_encode($c);
$e = $row['encode'];
$ca = $row['Catagory'];
$en = $row['encrypted'];

(Javascript) -Invokes SJCL-

<script type="text/javascript">
var content = <?php echo $con; ?>;
function decryptPaste() {
   try {
          sjcl.decrypt(document.getElementById("decrypt-pass").value, content)
   } catch (e) {
          alert("Can't decrypt: " + e);
   }}

Any and all help appreciated, thanks in advance!

0

There are 0 answers