You are not logged in.

Dear visitor, welcome to krpano.com Forum. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Thursday, March 17th 2016, 2:38pm

how to protect JS file

Hi,

I feel stupid, but can't seem to encrypt a simple JS file. This file only has some js functions, being called from a button on the HTML page with the embed viewer.
Perhaps that's the reason, should this JS file comply with certain standards (like the template for plugins )?

It works perfectly without this encryption. Only necessary for HTML5.
I am using the 1.19-pr3 (tried also 1.18), have the licenses included, just plain encryption (no private) and also created the viewer files with the same version.

What am I doing wrong or not seeing, please?

If it's not possible, what other solution would I have to not publicly show these functions?

Thanks!

Tuur

Sage

Posts: 3,186

Location: Netherlands

Occupation: Krpano custom coding / Virtual Tours / Photography / Musician / Recording engineer

  • Send private message

2

Thursday, March 17th 2016, 2:58pm

Hi,

did you use <!-- --> in your js file somewhere?
Don't!
use //

Hope it helps

Tuur *thumbsup*
http://www.virtualtuur.com
Skype:studiotuur

3

Thursday, March 17th 2016, 3:42pm

Yep, I did. I will have a go at it straight away, will let you know.

Thanks Tuur!

4

Thursday, March 17th 2016, 4:08pm

Nope, that doesn't make a difference, still not working :-(

Cleaned of all comments, including the //
1. Tried with encrypted cleaned file: still no go.
2. Tried to compress clean file first with http://closure-compiler.appspot.com/home and then encrypt: nope, still no go..

What else could be missing?

Umalo

Professional

Posts: 1,048

Location: Osijek, Croatia, EU

  • Send private message

5

Thursday, March 17th 2016, 4:29pm


6

Thursday, March 17th 2016, 4:37pm

Thanks for joining in Umalo, but no, unfortunately that doesn't change things either...
(btw, it's -h5 right?).

Any other suggestions?

First of all, it should be possible right? Just a simpel JS file with only a (couple of) functions?

7

Thursday, March 17th 2016, 5:21pm

BTW, I tried it with another JS file as well, same problem. Similar stuff, just a couple of functions.

Are there any other ways?
I am now trying an Obfuscator, but would rather encrypt it of course..

8

Thursday, March 17th 2016, 10:49pm

Tried cleaning up even further (replacing double quotes with single ones, etc.), but still no luck. Tried all settings for the encrypttool via commandline, as well as krpanotools32 and krpanotools64 (I am on a 64bit machine), but still to no avail.

I can't get it to work unfortunately...
Has anybody actually been able to encrypt JS files successfully?

Tuur

Sage

Posts: 3,186

Location: Netherlands

Occupation: Krpano custom coding / Virtual Tours / Photography / Musician / Recording engineer

  • Send private message

9

Thursday, March 17th 2016, 11:55pm

yes i did
did you use the 'red iconed' Krpanotools encryption tool from the 19.pr3 package?
Maybe post your js file.. so we can see.

Tuur *thumbsup*
http://www.virtualtuur.com
Skype:studiotuur

10

Friday, March 18th 2016, 9:10am

Hi Tuur, thanks again for following up, much appreciated!

Yes, I did use the 'red iconed' Krpanotools, as well as via commandline with krpanotools32 and krpanotools64 directly.

You asking me for the code got me thinking to go back to basics, as I just tested a very simple Hello World script. Even this didn't work!
So, I am either missing something in the JS file, or I am calling it the wrong way, or I need to include it in a different way.

This is what I have, which works as long it is not encrypted:
1. JS file, only 1 function:

Source code

1
2
3
4
function down_img()
{
   alert ("Hello World!");
}


2. include in HTML HEAD:

Source code

1
<script src="../js/script.js"></script>


3. calling via a button in vtourskin:

Source code

1
<layer name="skin_btn_img" style="skin_img|skin_tooltips" tooltip="JPG Snapshot" align="left" x="125" y="0" scale="0.5" onclick="js(down_img());" devices="html5" />

Tuur

Sage

Posts: 3,186

Location: Netherlands

Occupation: Krpano custom coding / Virtual Tours / Photography / Musician / Recording engineer

  • Send private message

11

Friday, March 18th 2016, 10:20am

Try including the js file in the krpano xml instead of putting it in the index.html.
Then it will be read by krpano, and understands the encryption.
Not, sure but i think that is the problem.

Tuur *thumbsup*
http://www.virtualtuur.com
Skype:studiotuur

12

Friday, March 18th 2016, 1:20pm

Thanks Tuur, that sounds very logical. I will have a go at it as soon as possible and let you know..

Thanks!

Tuur

Sage

Posts: 3,186

Location: Netherlands

Occupation: Krpano custom coding / Virtual Tours / Photography / Musician / Recording engineer

  • Send private message

13

Friday, March 18th 2016, 2:19pm

Sorry.. that is probably not gonna work.

try to put the javascript in the xml, like:

Source code

1
2
3
4
5
<action name="test" type="Javascript" autorun="">
	<![CDATA[
		alert("Cheers from Holland");
	]]>
</action>



Tuur *thumbsup*
http://www.virtualtuur.com
Skype:studiotuur

This post has been edited 1 times, last edit by "Tuur" (Mar 18th 2016, 2:51pm)


14

Friday, March 18th 2016, 3:49pm

Mmmm, I am afraid that's gonna be difficult. Just tested it and a simple alert does indeed work, but my original script already fails on the second line:

var mycanvas = $('div canvas:first-child').get(0);
try{ ...... etc

(the try{ is not understood)

I will probably need to rewrite the whole script to 'krpano-speak' ? Does it accept normal Javascript?
This script is not too difficult (I hope) to rearrange, but I have another one with all kinds of calculations which will be much more difficult if I need to rewrite that...

15

Friday, March 18th 2016, 7:01pm

HANG ON! That's perfectly working!

I only had to remove a couple of 'return;' statements in the script, apparently those are not allowed. And to change 'function' by '<action etc.>' of course.

I am now going to try my big script with a lot of functions. Will let you know.

Still would like to know why I cannot encrypt the JS files though, even if it's only with 1 alert it won't work...

Thanks so far, you're a star!

16

Saturday, March 19th 2016, 2:23pm

Like I feared, stuck on the functions...

I can successfully call the following without a problem:

Source code

1
2
3
4
5
<action name="down_img" type="Javascript" autorun="">
<![CDATA[
alert('cheers');
]]>
</action>


from a button with

Source code

1
onclick="down_img();"


I can also successfully pass an argument like so:

Source code

1
2
3
4
5
<action name="down_img" type="Javascript" autorun="">
<![CDATA[
alert(args[1]);
]]>
</action>


with button:

Source code

1
onclick="down_img(cheers);"


BUT how do I pass on an argument/variable from action to action, which all contain JS scripts?

So with button:

Source code

1
onclick="down_img();"

And action1:

Source code

1
2
3
4
5
6
<action name="down_img" type="Javascript" autorun="">
<![CDATA[
var poptext="cheers";
popup(poptext);
]]>
</action>


and action2:

Source code

1
2
3
4
5
<action name="popup" type="Javascript" autorun="">
<![CDATA[
alert(args[1]);
]]>
</action>


I tried all kinds of variations of calling and passing, like:
krpano.call popup(args[1]);
call popup(args[1]);
krpano.call actions.popup(args[1]);
js(popup(args[1]));
etc.

also, tried
%1
args[1]

But to no avail. Any clue what to do?

This post has been edited 1 times, last edit by "LMB" (Mar 19th 2016, 2:40pm)


17

Sunday, March 20th 2016, 4:24pm

Mmmm... I feel rather stupid. Or perhaps not, but after dreaming about functions, I think I realise now how to do it. At least, a small test confirmed my idea :-)

I don't need to put all original functions into actions of course. My main action just needs to include all those functions, in plain JS code.

So, in my example, this works:

button remains:

Source code

1
onclick="down_img();"


1 action in its shortest form, just to prove a point:

Source code

1
2
3
4
5
6
7
8
9
<action name="down_img" type="Javascript" autorun="">
<![CDATA[
popup('cheers');

function popup(txt){
alert(txt);
}
]]>
</action>


I am happy again!

Of course, still would like to know 2 things, I hope Klaus can join in:
* why can I not encrypt JS files?
* how to pass on /arguments/variables from (JS-)action to (JS-)action?

Thanks again Tuur for keeping on the right track!

18

Monday, March 21st 2016, 1:02pm

still not there

Pfff... Spoke too soon... :-(

I still have a problem, and as far as I can tell, it's simply my lack of knowledge of the internal calls.

What I told before works, but only for a button inside the pano.
I actually have a button in the HTML page. Before I started fumbling around, I had the JS code inside the HTML working fine. Thát code I want to encrypt.
So at first I thought to put the code in a JS file and encrypt that. If I could that working, everything would be so easy. But I don't know how.
So, I put that code the JS-code inside an XML as 'type=javascript' and as long as I call that from a button within the pano, I am OK.

But how do I call that function from this button in the HTML? I tried simply calling the action, but since it is JS code it won't take it. Other things I tried:
js(actionfunction);
jscall(actionfunction);
krpano.call actionfunction();
etc.

What would be the syntax, please?

To reiterate what I have:
1.button in HTML:

Source code

1
<span id="Button" class="myButton" onclick="actionFunction();">buttontest</span>


2. XML:

Source code

1
2
3
4
5
<action name="actionFunction" type="Javascript" autorun="">
<![CDATA[
alert('hello');	
]]>
</action>

19

Monday, March 21st 2016, 5:31pm

Hi,

only krpano files (e.g. xml files or krpano html5 .js plugins) could be encrypted - these files will be loaded and decrypted by the krpano viewer and run inside krpano.

Any external .js files on .html webpage itself are outside of krpano and can't be encrypted - the browser alone wouldn't know that to do with such files.

If you want to call krpano actions from html, the JS-Interface need to be used:
http://krpano.com/docu/js/#top

e.g.
in the xml:

Source code

1
2
3
<action name="do_something">
...
</action>


in the html:

Source code

1
<span ... onclick="document.getElementById("krpanoSWFObject").call('do_something()');">...</span>



Or if you just want to project/encrypt your Javascript functions and then use them normally in the .html:
  1. make a Javascript action inside the xml
  2. set autorun="preinit"
  3. add all your functions to the 'window' object
E.g. in the (encrypted) xml:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
<action name="my_hidden_js_functions" type="Javascript" autorun="preinit"><![DATA[

window.do_something = function()
{
  ...
}

window.do_something_else = function()
{
  ...
}

]]></action>


and in the html (but only after krpano is loaded):

Source code

1
<span ... onclick="do_something();">...</span>


Best regards,
Klaus

20

Monday, March 21st 2016, 7:33pm

thanks Klaus!
It all makes sense.

I was halfway there, but still a bit guessing and stuck. Thank you so much!
And good to know I should not look further into encrypting external JS.

Since I am programming for HTML5 only, is there a simple example (other than that of the plugins template) of the JS plugin? And what makes it that a JS plugin can be encrypted, but an external JS not?

This post has been edited 2 times, last edit by "LMB" (Mar 21st 2016, 9:12pm)


Similar threads