0

This question knowing that obfuscation is by no means a strong way to protect code...

Using Gulp, I'm looking for a way to prevent my app's content to appear in a too obvious manner. Not manipulating sensitive data, but I'd still not want my minified code to look too obvious to modify.

Been trying gulp-minify and gulp-uglify, but either my use of them is wrong, either they don't fill my need.

Needs being: - function renaming - variable renaming - string obfuscation (at least prevent the string from being human readable at first glance) - not more than 2x the storage needs

What would be the suggested approaches, leads, plugins?

Thanks in advance,

Jem
  • 6,226
  • 14
  • 56
  • 74
  • Thanks. These solutions don't work either, I'll review my process step by step. Bust be an issue in there somewhere. – Jem May 22 '17 at 14:20

3 Answers3

2

Just try this: Javascript Obfuscator. As far as I know, it's almost impossible to revert the obfuscated code back to the original.

Buzy Bug
  • 51
  • 4
1

So far, the most effective (in my case) is to pipe the following code, which just applies character rotation:

    function obfuscate(text, key, n = 126) {
        // return String itself if the given parameters are invalid
        if (!(typeof(key) === 'number' && key % 1 === 0)
            || !(typeof(key) === 'number' && key % 1 === 0)) {
            return text.toString();
        }

        var chars = text.toString().split('');

        for (var i = 0; i < chars.length; i++) {
            var c = chars[i].charCodeAt(0);

            if (c <= n) {
                chars[i] = String.fromCharCode((chars[i].charCodeAt(0) + key) % n);
            }
        }

        return chars.join('');
    },

    function defuse(text, key, n = 126) {
        // return String itself if the given parameters are invalid
        if (!(typeof(key) === 'number' && key % 1 === 0)
            || !(typeof(key) === 'number' && key % 1 === 0)) {
            return text.toString();
        }

        return obfuscate(text.toString(), n - key);
    }
Jem
  • 6,226
  • 14
  • 56
  • 74
1

You may want to consider gulp-javascript-obfuscator. It's a node module and version ^1.1.5 worked very well for me. It also has the option to minify with the following code:

// Imports ...
obfuscator    = require('gulp-javascript-obfuscator') 

// ... Other code 

gulp.src('my_file.js')
.pipe(obfuscator({compact:true}))
.pipe(gulp.dest('dist'));
Ithar
  • 4,865
  • 4
  • 39
  • 40
  • var gulp = require('gulp'); var pipelines = require('readable-stream').pipeline; const javascriptObfuscator = require('gulp-javascript-obfuscator'); gulp.task('min-js', function () { return pipelines( gulp.src('js/*.js'), javascriptObfuscator(), gulp.dest('dist') ); }); – heeraj123 Sep 17 '21 at 07:35