問題描述
這與安全無關.也不是讓它難以打破.我正在尋找一種簡單的算法來以一種與原始字符串不同的方式更改字符串(網址).加密 將使用 javascript 完成.然后我想將 encrypted 字符串提供給 PHP 函數以將其更改回原始字符串.兩端可以共享一個密鑰,或者轉換可以是無密鑰的,只依賴于邏輯.
This is not about security. It is also not to make it hard to break. I'm looking for a simple algorithm to change a string (a url) in a way it does not resemble the original. The encryption will be done with javascript. Then I want to feed the encrypted string to a PHP function to change it back to the original. Both ends could share a secret key, or the conversions could be key-less and rely on just logic.
理想的解決方案
- 會很簡單
- 將使用可用的 javascript 函數進行加密
- 將使用可用的 php 函數進行解密
- 將生成與純文本完全不同的加密字符串
- 將只在加密字符串中使用小寫字母字符和數字
- 不是像 Base64-ing 那樣廣泛使用的加密方法.
最后一個要求是在shamittomar 的回答.
The last requirement was added after shamittomar's answer.
推薦答案
如果這正是您想要的,您可以Base64 對其進行編碼和解碼.
If that's what you want, you can Base64 encode and decode that.
:在 OP 澄清之后:
由于您不想要廣泛使用的方法,這里有一種很少使用的方法,它可以通過僅以小寫字母和數字給出輸出來為您完成.它是Base32 編碼/解碼.使用以下庫:
As you do not want widely used methods, here is one rarely used method and that can do it for you by giving output only in LOWERCASE letters and NUMBERS. It is Base32 Encode/Decode. Use the following libraries:
- Javascript Base32 編碼器:http://www.tumuski.com/2010/04/啃食者/
- PHP Base32 解碼器:https://www.phpclasses.org/package/3484-PHP-Encode-and-decode-data-with-MIME-base-32-encoding.html
這篇關于簡單的 Javascript 加密,PHP 使用共享密鑰解密的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!