简体   繁体   中英

Avoid revealing source code for CSHTML and javascript

I have the following code:

<html>
  <head>
  </head>
   <body>
    <!-- some more CSHTML code here -->
    <script src="https://js.braintreegateway.com/v1/braintree.js"></script>
    <script>
        var braintree = Braintree.create("SOME RANDOM KEY");
        braintree.onSubmitEncryptForm('braintree-payment-form');
    </script>
  </body>
</html>

I want to be able to do the script without revealing the key string in the source. I have a key, but I don't want it to be revealed. Is there a safe and secure way to access a string by reference (preferably from a C# file)? Sort of like:

    <script>
        var braintree = Braintree.create(somefile.getString("string_key"));
        braintree.onSubmitEncryptForm('braintree-payment-form');
    </script>

If the code runs on the client, the key cannot be completely secure. A determined user could monitor network traffic and watch for the key when it arrived, or do one of 100 other things to compromise the key.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM