Troubles encountered while implementing crypto-js in Parse Cloud Code for an iOS mobile app

For my iOS app, I have implemented Parse as the backend and want to ensure the data transmitted between Parse and the device is encrypted. To achieve this, I have turned to Parse Cloud Code for server-side encryption and decryption of all data exchanges.

While Parse offers a 'crypto' module by default, I couldn't locate any documentation for it. Hence, I decided to use crypto-js and incorporated the necessary files for AES encryption and decryption into the Parse Cloud Code /cloud directory.

The challenge arises when I receive the output from crypto-js's AES functions, as I'm uncertain about the type of object being returned. It appears to be an NSDictionary object, although I expected either an NSString or NSData. This discrepancy has left me puzzled on how to proceed further.

If possible, kindly advise on any additional details required or point out any potential misconceptions I might have. Your assistance will be greatly appreciated.

Answer №1

To ensure secure communication on the server side, I implemented encryption and decryption in my cloud code that resembles nodeJS scripting:

var crypto = require('crypto');
var algorithm = "aes-128-cbc"; //select preferred algorithm from http://nodejs.org/api/crypto.html
var password = "securePassphrase";
var cipher = crypto.createCipher(algorithm,password);
var decipher = crypto.createDecipher(algorithm,password);
exports.customEncryption = {
    encrypt:function(data){
        var encryptedData = cipher.update(data,'utf8','hex')
        encryptedData += cipher.final('hex');
        return encryptedData;
    },
    decrypt: function(encryptedData){
        var decryptedData = decipher.update(encryptedData,'hex','utf8')
        decryptedData += decipher.final('utf8');
        return decryptedData;
    }
};

If you save this script as "cloud/encryption.js", you can utilize the encryption tool within your cloud code as follows:

var data = "encryptThis";

var encryptionTool = require("cloud/encryption.js").customEncryption;
var encryptedResult = encryptionTool.encrypt(data);
var decryptedResult = encryptionTool.decrypt(encryptedResult);

if (decryptedResult == data){
     //Input matches the decrypted data
}

Answer №2

All data transmitted through Parse is encrypted using SSL, which provides sufficient security for communications.

While it may be tempting to encrypt data stored on the server, it is important to have a strong understanding of cryptographic security before attempting to do so.

It is crucial that plain or encrypted passwords are never stored; instead, store a properly salted and hashed version of the password to enhance security.

If your data is highly valuable, consider consulting a security expert to design a comprehensive security plan. Achieving strong security measures can be challenging, and even one mistake can render all efforts ineffective.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

jQuery does not change the scroll position of elements

I'm looking to implement a feature on my website where certain points act as "magnets" and when the user is near one of these points, the window automatically scrolls to the top. I found a jQuery plugin that does something similar which you can check ...

Tips for positioning a highcharts pie chart and legend in the middle of a page

I'm struggling to center my highchart data in a node/react single page application. Currently, it appears off-center like this: https://i.stack.imgur.com/ccR6N.png The chart is floating to the left and I would like to have everything centered within ...

Using PHP and jQuery to generate push notifications can result in issues with server performance

To simulate push notifications using PHP, I have implemented the following method: An AJAX call is made to a server-side script using jQuery. The script includes a for loop with a sleep function after each iteration to introduce delay. If a certain condi ...

What order does JavaScript async code get executed in?

Take a look at the angular code below: // 1. var value = 0; // 2. value = 1; $http.get('some_url') .then(function() { // 3. value = 2; }) .catch(function(){}) // 4. value = 3 // 5. value = 4 // 6. $http.get('some_url') ...

set up the router by defining the behavior for each route

My goal is to redirect the user back to the homepage when they click the browser's back arrow to return to the previous page. However, I'm facing an issue where I cannot go back to the previous page when I'm on the login page using the brow ...

Exporting a function from Vue's `<script setup>` is similar to exporting from a module

I am trying to export a function from a component within the component itself and then use it in another component. My attempt looks like this: <!-- TestHeading.vue --> <template> <h1>{{ title }}</h1> </template> <scrip ...

Display the React component following a redirect in a Next.js application that utilizes server-side rendering

Just starting out with next.js and encountering a problem that I can't seem to solve. I have some static links that are redirecting to search.tsx under the pages folder. Current behavior: When clicking on any of the links, it waits for the API respo ...

Determine if two arrays share the same keys

Looking to compare two arrays and update them with matching keys while adding 0 for non-matching keys. For example: let obj1 = [ {"type": "Riesenslalom","total": 2862}, {"type": "Slalom", "total" ...

jQuery load() issue

$('form.comment_form').submit(function(e) { e.preventDefault(); var $form = $(this); $.ajax({ url : 'inc/process-form.php', type: 'POST', cache: true, data:({ comment ...

What is the best way to insert a hyperlink into the header of a column in a React table that is built using Material

// Here is the header const dataCells = [ {id:"Customer_ID",label:"CustomerId"}, {id:"Type", label: "Type"}, {id:"First_Name", label: "First Name"}, {id:"Last_Name", labe ...

Display the div only if the content matches the text of the link

Looking for a way to filter posts on my blog by category and display them on the same page without navigating away. Essentially, I want users to click on a specific tag and have all posts with that tag show up. Since the CMS lacks this functionality, I pla ...

The watch functionality is failing to work within a specialized attribute directive that is being utilized within a separate custom element directive

I'm currently working with two directives that handle separate functionalities. I am attempting to utilize the attribute directive within an element directive, but I'm encountering issues with the watch function not working on the attribute direc ...

React conditional statement within a map function embedded in a JSX element

Below is the function I have created to generate tabbed items: function ConstructTabs(props) { const tabs = props.tabs; const makeTabs = tabs.map((tab, index) => { <React.Fragment> <input className="input-tabs" id ...

Having trouble getting the default NextJS template to work with TailwindCSS

Sysinfo: > Windows 11 > Node: v18.16.0 > Next: 13.4.13 > Tested Browser: Firefox, Chrome. Step to Reproduce To recreate the issue, I created a NextJS project using the command npx create-next-app tezz with specific options selected: Would you ...

Converting a comma-separated string into an array of integers using jQuery

Is there a way in jQuery to convert a string containing multiple numbers into an array? The string in question is as follows: let values = "901,235,342,421,345,745,544,324,445,123,232,986,345,678"; ...

When working with three.js, I am able to successfully display a .glb 3D model locally. However, when trying to view it on the GitHub server

While working on my personal webpage, I attempted to use three.js to showcase a 3D model. The model appeared successfully on my local server, but failed to display on my web server, resulting in an error message similar to the following: https://i.sstatic. ...

The grpc client is not able to receive the data being streamed from the

I've been attempting to stream the output of a nodejs child process through grpc, but I consistently receive an empty result. Here is my proto file: syntax = "proto3"; package servicePackage; service Mobile { rpc sign(Empty) returns ( ...

Create an array that mimics another array but only for certain items

I'm attempting to create a new array that contains specific objects from another array. Essentially, I want the first array to only hold objects that meet a certain criteria from the second array, which is populated with many objects. I need this new ...

Arrange JSON data in ascending order based on the dates, starting with the most recent date, by utilizing jquery

I'm in need of assistance on sorting a list of articles from an external json file based on their creation date. Can anyone provide guidance? Currently, I am fetching the data using AJAX and displaying only 6 results, but I'm facing difficulties ...

Learn how to effortlessly download a file from Amazon S3 using Angular and ng-click technology

When attempting to download a file from my Amazon S3 bucket using Angular's ng-click, I am receiving a blank file instead of the expected content. HTML <div class="details-field"> RC Book <font class="digit" >({{rcCount}})</font> ...