I have this code in an html page (JavaScript):
<script>
var cox,d = 0;
Console.Log(cox,d);
</script>
Now I encrypted [var cox,d = 0; Console.Log(cox,d);]
manually with base64 encode and the result is this: IHZhciBjb3gsZCA9IDA7DQogQ29uc29sZS5Mb2coY294LGQpOw==
I want that this encoded string (the code) could be executed by another JavaScript function in the same page... example:
<script>
var encoded = "IHZhciBjb3gsZCA9IDA7DQogQ29uc29sZS5Mb2coY294LGQpOw==";
var decodedString = atob(encoded);
/* Problem is here */
</script>
I want to execute the JavaScript code (encoded above) in /* Problem is here */
'.
How can I do?
I have this code in an html page (JavaScript):
<script>
var cox,d = 0;
Console.Log(cox,d);
</script>
Now I encrypted [var cox,d = 0; Console.Log(cox,d);]
manually with base64 encode and the result is this: IHZhciBjb3gsZCA9IDA7DQogQ29uc29sZS5Mb2coY294LGQpOw==
I want that this encoded string (the code) could be executed by another JavaScript function in the same page... example:
<script>
var encoded = "IHZhciBjb3gsZCA9IDA7DQogQ29uc29sZS5Mb2coY294LGQpOw==";
var decodedString = atob(encoded);
/* Problem is here */
</script>
I want to execute the JavaScript code (encoded above) in /* Problem is here */
'.
How can I do?
Share Improve this question edited Feb 5, 2018 at 15:19 Rafik Tighilt 2,1011 gold badge16 silver badges27 bronze badges asked Feb 5, 2018 at 14:22 ProgrammerProgrammer 1011 silver badge9 bronze badges 3-
2
Just being pedantic, encoding with BASE64 and encrypting is not the same thing at all. I think you want to use
eval
- but that is a slippery slope :) – Morten Jensen Commented Feb 5, 2018 at 14:27 -
2
You know that
Console
!=console
– Jonas Wilms Commented Feb 5, 2018 at 14:39 - my pc changed it from console to Console automatically because I coded it on stack overflow not on an editor first.... – Programmer Commented Feb 5, 2018 at 19:11
1 Answer
Reset to default 6You can use the eval function (it is not remended), but it solves your problem.
/* var cox,d = 0; console.log(cox,d); */
var encoded = "dmFyIGNveCxkID0gMDsgY29uc29sZS5sb2coY294LGQpOw==";
var decodedString = atob(encoded);
eval(decodedString);
Another way of doing it, is using the New Function constructor
/* var cox,d = 0; console.log(cox,d); */
var encoded = "dmFyIGNveCxkID0gMDsgY29uc29sZS5sb2coY294LGQpOw==";
var decodedString = atob(encoded);
var func = new Function(decodedString);
func();
*When encodeding your code, Console and Log must be lowercase and not ucfirst.
I am not a security expert, and I truely advice you to check the risks of evaluating and executing this kind of functions in your apps.
Here is an interesting answer about the difference between eval
and new Function
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744572732a4581551.html
评论列表(0条)