Ejemplo n.º 1
1
        static void OriginalMain()
        {
            var done = false;
            var sw = new Stopwatch();

            sw.Start();
            for (var i = 0; i < N; i++)
            {
                var jintEngine = new Jint.Engine();
                jintEngine.Execute(currentScript);
                done = jintEngine.GetValue("done").AsBoolean();
            }
            sw.Stop();
            Console.WriteLine("jint: " + sw.ElapsedMilliseconds / N + " - " + done);

            done = false;
            sw.Restart();
            for (var i = 0; i < N; i++)
            {
                var ironjsEngine = new IronJS.Hosting.CSharp.Context();
                ironjsEngine.Execute(currentScript);
                done = ironjsEngine.GetGlobalAs<bool>("done");
            }
            sw.Stop();
            Console.WriteLine("ironjs: " + sw.ElapsedMilliseconds / N + " - " + done);

            done = false;
            sw.Restart();
            for (var i = 0; i < N; i++)
            {
                using (var jsNetEngine = new Noesis.Javascript.JavascriptContext())
                {
                    jsNetEngine.Run(currentScript);
                    done = (bool)jsNetEngine.GetParameter("done");
                }
            }
            sw.Stop();
            Console.WriteLine("js.net: " + sw.ElapsedMilliseconds / N + " - " + done);

            done = false;
            sw.Restart();
            for (var i = 0; i < N; i++)
            {
                var jurassicEngine = new Jurassic.ScriptEngine();
                jurassicEngine.Execute(currentScript);
                done = jurassicEngine.GetGlobalValue<bool>("done");
            }
            sw.Stop();
            Console.WriteLine("jurassic: " + sw.ElapsedMilliseconds / N + " - " + done);

            done = false;
            sw.Restart();
            for (var i = 0; i < N; i++)
            {
                using (var clearscriptV8 = new Microsoft.ClearScript.V8.V8ScriptEngine())
                {
                    clearscriptV8.Execute(currentScript);
                    done = clearscriptV8.Script.done;
                }
            }
            sw.Stop();
            Console.WriteLine("clearscriptV8: " + sw.ElapsedMilliseconds / N + " - " + done);

            done = false;
            sw.Restart();
            using (var clearscriptV8 = new Microsoft.ClearScript.V8.V8Runtime())
            {
                var compiled = clearscriptV8.Compile(currentScript);
                for (var i = 0; i < N; i++)
                {
                    using (var engine = clearscriptV8.CreateScriptEngine())
                    {
                        engine.Evaluate(compiled);
                        done = engine.Script.done;
                    }
                }
            }
            sw.Stop();
            Console.WriteLine("clearscriptV8 compiled: " + sw.ElapsedMilliseconds / N + " - " + done);

            done = false;
            sw.Restart();
            for (var i = 0; i < N; i++)
            {
                var nilcontext = new NiL.JS.Core.Context();
                nilcontext.Eval(currentScript);
                done = (bool)nilcontext.GetVariable("done");
            }
            sw.Stop();
            Console.WriteLine("niljs: " + sw.ElapsedMilliseconds / N + " - " + done);

            Console.Read();
        }
Ejemplo n.º 2
0
        public void Init()
        {
            Context = new Noesis.Javascript.JavascriptContext();

            var sjcl  = GetJavascriptSource("sjcl.min.js");
            var utils = GetJavascriptSource("utils.min.js");
            var sha3  = GetJavascriptSource("sha3.min.js");

            var decrypt_v2 = @"function deCryptV2(data, password) {
	                        var saltBits = sjcl.codec.base64.fromBits(sjcl.codec.hex.toBits(keccak_256(password).slice(0,32)));
	                        var iv = sjcl.codec.base64.fromBits(sjcl.codec.hex.toBits(keccak_256(password).slice(32,64)));
	                        var derivedKey = sjcl.misc.pbkdf2( keccak_256(keccak_256(password)), saltBits, 50000, 256 );
	                        return sjcl.decrypt(derivedKey, JSON.stringify({ v:1, iv:iv, salt:saltBits, ks:256, ts:128, mode:""ccm"", cipher:""aes"", ct:sjcl.codec.base64.fromBits(sjcl.codec.hex.toBits(data)) }));
                        }";

            var decrypt_v3 = @"
	            function _genKeysV3(plainPassword) {
		            if ( typeof(plainPassword) === '' ) { throw new Error(""Password is not initialized!""); }

                    var bn = sjcl.bn.fromBits(sjcl.misc.pbkdf2(keccak_256(keccak_256(plainPassword)), sjcl.codec.base64.fromBits(sjcl.codec.hex.toBits(keccak_256(plainPassword).slice(0, 32))), 50000, 512));
                        bn = bn.mod(sjcl.ecc.curves.c384.r);
                    return sjcl.ecc.elGamal.generateKeys(sjcl.ecc.curves.c384, 6, bn);
                }
                function deCryptV3(plainPassword, msg) {
		            return sjcl.decrypt(new sjcl.ecc.elGamal.secretKey(sjcl.ecc.curves.c384, sjcl.bn.prime.p384.fromBits(_genKeysV3(plainPassword).sec.get())), msg);
	            }"    ;

            var decrypt_v4 = @"
                function _genKeysV4(plainPassword) {
		            if ( typeof(plainPassword) === '' ) { throw new Error(""Password is not initialized!""); }

                    var bn = sjcl.bn.fromBits(sjcl.misc.pbkdf2(keccak_256(keccak_256(plainPassword)), sjcl.codec.hex.toBits(keccak_256(plainPassword).slice(0, 32)), 25000, 2048));
                        bn = bn.mod(sjcl.ecc.curves.c256.r);
                        return sjcl.ecc.elGamal.generateKeys(sjcl.ecc.curves.c256, 0, bn);
                }
                function deCryptV4(plainPassword, msg) {
                    var keys = this._genKeysV4(plainPassword);
		            return sjcl.decrypt(keys.sec, msg);
	            }"    ;

            var custom_keccak_256 = @"
                function keccak_256(message) {
                    return new Keccak(256, KECCAK_PADDING, 256).update(message)[""hex""]();
                }";


            this.Context.Run(sjcl);
            this.Context.Run(sha3);
            this.Context.Run(custom_keccak_256);
            this.Context.Run(decrypt_v2);
            this.Context.Run(decrypt_v3);
            this.Context.Run(decrypt_v4);
        }
Ejemplo n.º 3
0
 public static string JSON2RJSON(string inpJson) {
   using (var js = new Noesis.Javascript.JavascriptContext()) {
     js.SetParameter("inputJson", inpJson);
     var script =
       File.ReadAllText(Machines.basicPath + @"rew\Web4\JsLib\Scripts\json2.js") + "\r\n" +
       File.ReadAllText(Machines.basicPath + @"rew\Web4\JsLib\JS\External\RJSON.js") + "\r\n" +
       "var obj = JSON.parse(inputJson); var packed = RJSON.pack(obj); outputJson = JSON.stringify(packed);";
     try {
       js.Run(script);
     } catch (Exception exp) {
       throw exp;
     }
     return (string)js.GetParameter("outputJson");
   }
 }
 /// <summary>
 /// Initialize the context for Noesis JavaScript run-time
 /// </summary>
 /// <param name="javascriptContext"></param>
 public DynamicJavascriptContext(Noesis.Javascript.JavascriptContext javascriptContext)
 {
     _javaScriptContextImplementation = new NoesisJavaScriptContextImplementation(javascriptContext);
     DynamicJavaScriptInstance.___globalJavaScriptContext = _javaScriptContextImplementation;
 }
        public NoesisJavaScriptContextImplementation(Noesis.Javascript.JavascriptContext javascriptContext){

            this._javascriptContext = javascriptContext;
        }
Ejemplo n.º 6
0
 private static void ExecuteWithJavascriptDotNet(Test test)
 {
     Execute("js.net", test, () =>
     {
         using (var jsNetEngine = new Noesis.Javascript.JavascriptContext())
         {
             jsNetEngine.Run(test.Content);
         }
     });
 }
Ejemplo n.º 7
0
 public NoesisJavaScriptContextImplementation(Noesis.Javascript.JavascriptContext javascriptContext)
 {
     this._javascriptContext = javascriptContext;
 }