admin管理员组文章数量:1389249
I have a client whom has a document full of javascript that they would like to encrypt. My idea is that I can create an php upload form for the unencrypted document and then it processes and gives the client back the encrypted document. Would it be possible to salt the code so that it will still work but not be able to be undone?
I have a client whom has a document full of javascript that they would like to encrypt. My idea is that I can create an php upload form for the unencrypted document and then it processes and gives the client back the encrypted document. Would it be possible to salt the code so that it will still work but not be able to be undone?
Share Improve this question edited Dec 7, 2011 at 23:44 ThinkingStiff 65.4k30 gold badges147 silver badges241 bronze badges asked Dec 7, 2011 at 23:22 Jess McKenzieJess McKenzie 8,39528 gold badges104 silver badges172 bronze badges 4- 2 Not possible. An irreversible encryption method will prevent a browser from parsing and showing your page. – Rob W Commented Dec 7, 2011 at 23:25
- 2 You should look in minifying the code if you want to obfuscate the logic. – Sam Dufel Commented Dec 7, 2011 at 23:26
- What exactly is a document? Is this like a Word or PDF file? – Ilia G Commented Dec 7, 2011 at 23:31
- As everyone has said so far, you can make it hard for people to get to your code but you cannot make it impossible. If the code can be executed, then it can be accessed, copied and modified. Think about how many billions have been spent on encryption by the movie industry, and their efforts have always been cracked and torn to pieces after a few months. It really is impossible. Even the source code for piled languages like C and Flash can be depiled by simply running it through freely available tools (the code produced is quite hard to read mind you). – Abhi Beckert Commented Dec 7, 2011 at 23:47
3 Answers
Reset to default 6No.
Essentially if your code is working it is being interpreted by the browser (and can be seen... at least partially).
You're best bet is to obfuscate your code.
On a side note, you could try what Jake said and simply redirect all *.js request to a php page (using .htaccess) which:
1. fopen's the file,
2. Reads it into a string,
3. encodes the string,
4. and then returns that.
Although that requires the client to have the key with which you encrypted the string. And once someone decrypts that js (to run it), they can steal it...
No, it's not possible: a browser can't run encrypted nonsense to which it has no decryption key. You have to give the browser valid code that it understands — either by sending it unencrypted code, or sending it encrypted code and the decryption key and code to do the decryption — and you can't prevent the user from getting access to the code that his browser is running.
You can obfuscate the code, however, to make it difficult for someone to read and understand while still being valid and runnable. There are tools that'll do things like remove all ments and rename variables to meaningless names. But with enough time and effort, someone could still figure out what the code does.
This is a pretty crazy idea, but you could require that the end user enter an encryption key within the browser, used to decrypt the code. You could then run eval() on the decrypted string to get the code loaded into memory. I don't know if requiring the end user to enter a key is viable in your case, but it so - it should work.
本文标签: phpCan I encrypt a javascript file and still have it run on the clientStack Overflow
版权声明:本文标题:php - Can I encrypt a javascript file and still have it run on the client? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744646948a2617451.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论