Are there any "reversible" pseudo hashing functions available in javascript? The reason I ask is because I'm bouncing a string around various parts of my application but the string contains characters that are incompatible with certain parts of the app. So I'd like to convert "152(/,blue-Test#" in to an alphanumeric string and then be able to convert it back to the original value later on.
Security etc is not important, it can be "crackable", the length of the hash can be variable, etc.
If the same function could be easily replicated in to a PHP function that would be perfect.
Have you considered HTML encoding the strings?
<?
echo htmlspecialchars(someString);
echo htmlspecialchars_decode("this -> "");
?>
http://php.mirrors.ilisys.com.au/manual/en/function.htmlspecialchars.php
This will let you pass strings around the app that would otherwise throw errors or inject code, and it is also reversible.
It's possible that URI encoding is enough for you (depending on exactly which characters you find undesirable). In JavaScript:
encodeURIComponent("152(/,blue-Test#")
Output:
"152(%2F%2Cblue-Test%23"
To reverse:
decodeURIComponent("152(%2F%2Cblue-Test%23")
Output:
"152(/,blue-Test#"
If you're bouncing a lot of information (say, an array) around your app, you'd probably be best off turning it into a JSON object. This lets you move information with structures in-tact.
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.