Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6620719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:08:21+00:00 2026-05-25T21:08:21+00:00

var Obj = {}; Obj.ID = e.row.ID; Obj.firstName = e.row.firstName; Obj.lastName = e.row.lastName; This

  • 0
var Obj = {};
Obj.ID = e.row.ID;
Obj.firstName = e.row.firstName;
Obj.lastName = e.row.lastName;

This is my object, and i save this object in a file. now before saving into file, i want to encrypt it and save and while reading i want to decrypt and read.

var newFile = FileSystemPath;
newFile.write(JSON.stringify(object));
  1. Should i encrypt the object before stringifying it or after it.
  2. What are the ways to encrypt an object in javascript. Any examples
    would be great.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T21:08:22+00:00Added an answer on May 25, 2026 at 9:08 pm

    You can’t really encrypt objects, but you can encrypt strings, so you should probably first do a object serialization (JSON.stringify) and then encrypt it with a symmetric encryption algorithm so you would be able to decode the object later.
    I can’t really provide a good example, because javascript will always have serious security problems (being a client-side programming language), and even if you try a rather complex algorithm (such as AES) it will still be vulnerable, because the user can just see your source code, thus see your encription/decription algorithms.
    If you just want to alter the string a bit so it can’t be deciphered on the first look, you can simply use some built-in javascript methods (such as encodeURI/decodeURI) or you can do some character replacements or even use salts.

    Here’s a sample demo of how you can “encrypt” an object :

    function encrypt(o, salt) {
        o = JSON.stringify(o).split('');
        for(var i = 0, l = o.length; i < l; i++)
            if(o[i] == '{')
                o[i] = '}';
            else if(o[i] == '}')
                o[i] = '{';
        return encodeURI(salt + o.join(''));
    }
    
     function decrypt(o, salt) {
        o = decodeURI(o);
        if(salt && o.indexOf(salt) != 0)
            throw new Error('object cannot be decrypted');
        o = o.substring(salt.length).split('');
        for(var i = 0, l = o.length; i < l; i++)
            if(o[i] == '{')
                o[i] = '}';
            else if(o[i] == '}')
                o[i] = '{';
        return JSON.parse(o.join(''));
    }
    
    var obj = {
        key : 'value',
        3 : 1
    };
    var salt = "some string here";
    var encrypted = encrypt(obj, salt);
    var decrypted = decrypt(encripted, salt);
    

    Of course, this is just an example and you should modify it in order to encrypt more complex objects, where you need to encrypt functions, or where the object has circular references.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assuming this JSON object: var obj = { set1: [1, 2, 3], set2: [4,
I want to traverse through JavaScript object's property var obj = { a: 'value1',
Here is an object: var obj = new function(){ this.prop = {}; } and
Is there an easier way to achieve the following? var obj = from row
I have an on object like so var obj = {}; function set() {
Is it like... var obj = new Object(); obj.function1 = function(){ //code } or
Objects in javascript throw me for a loop! In this set up... var obj
var obj = {} obj.__setitem__ = function(key, value){ this[key] = value * value }
Sometimes I'll see code like this: var Obj = Obj || {}; What does
Here is my object literal: var obj = {key1: value1, key2: value2}; How can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.