JavaScript 加密

发布于 2024-11-03 12:15:39 字数 289 浏览 1 评论 0原文

该脚本必须搜索网页内的字符串。但该脚本不应显示它正在搜索的字符串。我的意思是搜索字符串应该采用加密格式或任何其他格式。 但如果没有该搜索字符串,则不应显示网页,或者应在页面上显示错误。

我打算开发一个插件。如果有人在他们的网页中使用该插件,他们必须并且应该将我的名字或我的网站名称放在该页面中。

是否可能,如果可以,如何加密脚本内的文本(srikanth)以及如何在页面内搜索该字符串。

有多少种可能性可以用 javascript 或 jquery 将我的名字放在网页中,但它不应该像任何人在源代码中检查它时那样可见

the script has to search a string inside the webpage. but that script should not display what string that it is searching. I mean the search string should be in encrypted format or any other format.
but without that search string the webpage should not be displayed or it should display an error on page.

I am going to develop a plugin. If anybody using that plugin in their webpage they must and should place my name or my website name in that page.

is it possible, if so how to encrypt my text (srikanth) inside the script and how to search that string inside the page.

how many possibilities are there to place my name in a webpage with javascript or jquery but it should not visible as it is when anybody check it in source code

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

少跟Wǒ拽 2024-11-10 12:15:39

没有办法隐藏你的名字。如果浏览器可以看到它,那么任何用户也可以。

您可以按照自己喜欢的方式加密您的姓名。但当然,它需要在客户端解密才能实际进行搜索。因此,任何拥有 JavaScript 调试器的人都可以立即发现您的名字。

或者稍微晦涩一点,您可以在服务器端对您的名称进行哈希处理,在 JavaScript 中对页面内容进行哈希处理,然后进行搜索。给定一个合适的哈希值,发生冲突的机会就会很小。但是,使用调试器,您仍然可以毫无问题地找出搜索字符串。说实话,这听起来很荒谬。

无论你想要实现什么目标,都需要重新考虑。

There is no way of hiding your name. If the browser can see it, then so can any user.

You can encrypt your name anyway you like. But of course it needs to be decrypted client-side to actually do the search. So anyone with a javascript debugger could uncover your name in moments.

Or slightly more obscurity you could hash your name server-side, in javascript hash the page contents, and then do your search. Given a decent hash the chance of collisions will be small. However, with a debugger you could still figure out the search string no problem. And to be honest this just sounds absurd.

Whatever you're trying to achieve needs to be re-thought.

薄荷港 2024-11-10 12:15:39

任何人都可以查看 Javascript 源代码,因此实际上不可能以安全的方式使用 Javascript 来加密某些内容。你可以混淆它,通常以可怕的方式,但它总是有可能逆转。

如果可以,请在服务器上执行任何需要一定程度安全性的操作。

Anyone can view Javascript source code, therefore it's not really possible to encrypt something using Javascript in a way that is secure. You can obfuscate it, often in horrible ways, but it's always possible to reverse.

If you can, do anything requiring a modicum of security on the server.

唐婉 2024-11-10 12:15:39

由于您无法真正加密一段文本,因此您可以混淆搜索并进行检查。

<!doctype html public "-//w3c//dtd html 3.2 final//en">
<html>
<head>
<!-- some simple styling so the div element does not appear, 
you could equally use a hidden form field and not require the styling -->
<style>#h3llo{display:none;}</style>
</head>
<body>
<div>Hello Some simple text
<form action="#" method="post" onSubmit="dosearch();return false;">
    <input type="text" id="searchfield" />
    <input type="button" name="submit" value="search" onClick="dosearch();return false;" />
</form>
</div>
<div id="h3llo"></div>
<script>
function d2h(d) {return d.toString(16);}
function h2d(h) {return parseInt(h,16);}
// converts the input string into hex vals
function Str2Hex(inputvars) {
  var tmp = inputvars;
  var str = '';
  for (var i=0; i<tmp.length; i++) {
    c = tmp.charCodeAt(i);
    str += '\\x' + d2h(c);
  }
  return str;
}
// converts the input field h3llo back to a string
function Hex2Str() {
  var tmp = document.getElementById('h3llo').innerHTML;
  var arr = tmp.split('\x');
  var str = '';
  for (var i=1; i<arr.length; i++) {
    c = String.fromCharCode(h2d(arr[i]));
    str += c;
  }
  return str.trim();
}
// fills the h3llo field with the encoded string
function populate(inputvars){document.getElementById('h3llo').innerHTML = Str2Hex(inputvars);}
// checks that the submitted search string matches the encoded string
function check(inputval){if(Hex2Str().toString() != inputval.toString()){ alert("Warning: '" + Hex2Str().toString() + "' != '" + inputval.toString() + "'");}else{alert("success");}}
// the action that fills the hidden field and checks the encoded value is the same
function dosearch(){var sval = String(document.getElementById('searchfield').value);populate(sval); check(sval);}
</script>
</body>
</html>

如果有人查看源代码,他们第一眼将无法看到搜索字符串,尽管正如之前提到的,这很容易逆转,但对于临时查看者来说,这会造成混淆。此外,如果编码数据被 css 隐藏(如本例所示)或隐藏表单字段,则它永远不会出现在未编码的页面或源上。

As you cant really encrypt a piece of text you can obfuscate the search and do a check.

<!doctype html public "-//w3c//dtd html 3.2 final//en">
<html>
<head>
<!-- some simple styling so the div element does not appear, 
you could equally use a hidden form field and not require the styling -->
<style>#h3llo{display:none;}</style>
</head>
<body>
<div>Hello Some simple text
<form action="#" method="post" onSubmit="dosearch();return false;">
    <input type="text" id="searchfield" />
    <input type="button" name="submit" value="search" onClick="dosearch();return false;" />
</form>
</div>
<div id="h3llo"></div>
<script>
function d2h(d) {return d.toString(16);}
function h2d(h) {return parseInt(h,16);}
// converts the input string into hex vals
function Str2Hex(inputvars) {
  var tmp = inputvars;
  var str = '';
  for (var i=0; i<tmp.length; i++) {
    c = tmp.charCodeAt(i);
    str += '\\x' + d2h(c);
  }
  return str;
}
// converts the input field h3llo back to a string
function Hex2Str() {
  var tmp = document.getElementById('h3llo').innerHTML;
  var arr = tmp.split('\x');
  var str = '';
  for (var i=1; i<arr.length; i++) {
    c = String.fromCharCode(h2d(arr[i]));
    str += c;
  }
  return str.trim();
}
// fills the h3llo field with the encoded string
function populate(inputvars){document.getElementById('h3llo').innerHTML = Str2Hex(inputvars);}
// checks that the submitted search string matches the encoded string
function check(inputval){if(Hex2Str().toString() != inputval.toString()){ alert("Warning: '" + Hex2Str().toString() + "' != '" + inputval.toString() + "'");}else{alert("success");}}
// the action that fills the hidden field and checks the encoded value is the same
function dosearch(){var sval = String(document.getElementById('searchfield').value);populate(sval); check(sval);}
</script>
</body>
</html>

If someone viewed the source they wouldn't at first glance be able to see the search string, though as it has mentioned before this would be easy to reverse it would obfuscate from the casual viewer. Also If the encoded data was hidden by css as in this example or a hidden form field it would never appear on the page or source un-encoded.

仙女 2024-11-10 12:15:39

我正在开发一个库来简化我的日常任务,其中之一就是加密。
我使用凯撒加密进行元素加密。

您可以下载缩小文件并将其包含在您的 html 中。

用法就像:

<!DOCTYPE HTML>
<html>

<head>
  <title>
    Element Encryption
  </title>
  <script type="text/javascript" src="https://raw.githubusercontent.com/Amin-Matola/domjs/master/dom-v1.0.0/dom.min.js"></script>
</head>

<body>
  <h1>Let's encrypt the element data</h1>
  <p>You may encrypt this paragraph data</p>
  <p>This is another paragraph you may encrypt too</p>

  <footer>
    <!--------- You may include your js here ------------->
    <script type="text/javascript">
          d("p").encrypt(text = "", depth = 10);
    </script>

  </footer>
</body>

</html>

I am developing a library to simplify my daily tasks, and one of which is encryption.
I am using caesar encryption for element encryptions.

you may download the minified file and include it in your html.

The usage is like:

<!DOCTYPE HTML>
<html>

<head>
  <title>
    Element Encryption
  </title>
  <script type="text/javascript" src="https://raw.githubusercontent.com/Amin-Matola/domjs/master/dom-v1.0.0/dom.min.js"></script>
</head>

<body>
  <h1>Let's encrypt the element data</h1>
  <p>You may encrypt this paragraph data</p>
  <p>This is another paragraph you may encrypt too</p>

  <footer>
    <!--------- You may include your js here ------------->
    <script type="text/javascript">
          d("p").encrypt(text = "", depth = 10);
    </script>

  </footer>
</body>

</html>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文