GithubHelp home page GithubHelp logo

kevinselwyn / encryptscript Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 1.0 5.85 MB

A secure, encrypted Javascript format (almost)

License: GNU General Public License v3.0

JavaScript 77.20% PHP 18.59% Shell 4.20%

encryptscript's Introduction

Encryptscript

A secure, encrypted Javascript format (almost)

Almost?

Thanks to modern browser inspectors (Chrome Inspector, FireBug, etc.), it is virtually impossible to execute Javascript with eval() that will remain hidden from a somewhat competent user.

There are additional factors in place that will hinder the most tenacious inspectors.

Demo

Encryptscript

Usage

Include the script in your document:

<script src="path/to/encryptscript.min.js"></script>

(Note: The un-minified, un-uglified, un-compressed version includes a few annoying obfuscations and hindrances, but the minified, uglified, compressed version should hinder even more.)

The script will look for all Encryptscript files included the following way:

<script type="application/encryptscript" src="path/to/hello.es"></script>

Security

On its own, including the script with the syntax above is not enough to execute the Encryptscript.

Because Encryptscript uses AES-128-CBC encryption, a key and iv (initialization vector) are needed to decrypt properly.

It will look for browser cookies named key and iv respectively and use their values in the decryption process.

Both cookies' values should be 16-byte hex strings (32 characters). Ex:

document.cookie="key=0102030405060708090a0b0c0d0e0f10";
document.cookie="iv=0102030405060708090a0b0c0d0e0f10";

Options

You can use the async attribute on the Encryptscript <script> tag to execute asynchronously.

If this attribute is not set, the scripts will queue one after the other.

Format

The Encryptscript format is just normal Javascript that has been encrypted with AES-128-CBC and converted to Base64.

You can generate them with OpenSSL:

KEY=0102030405060708090a0b0c0d0e0f10
IV=0102030405060708090a0b0c0d0e0f10

cat input.js | openssl enc -aes-128-cbc -K ${KEY} -iv ${IV} | openssl enc -base64 -A -out output.es

Encrytscript files must be served up with the correct MIME type. Add the type in your .htaccess:

AddType application/encryptscript es

If longer loading times are not an issue, you can create Encryptscript files on the fly with PHP.

Make sure that you set the content type:

header("Content-Type: application/encryptscript");

Then you can use openssl_encrypt() to encrypt your Javascript.

(Note: There is no need to Base64 encode the result of openssl_encrypt() because it outputs in Base64 by default)

Dependencies

Encryptscript depends on JES for AES decryption.

Support

  • IE8+
  • Chrome
  • Firefox
  • Safari
  • Opera

Is this really secure?

No, silly. Don't use this in production.

encryptscript's People

Contributors

kevinselwyn avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

fangbei

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.