I am currently running my website in shared hosting, and I am not able to register TLS/SSL for my website. However, I implemented jsencrypt
[A Javascript library to perform OpenSSL RSA Encryption, Decryption, and Key Generation] to encrypt all form data by AJAX or normal POST/GET.
Currently, I got into an issue with password reset link or some other important links that I sent to user for important actions regarding user account. For example:
example.com/password?resetcode=%CODE%
But After thinking of TLS/SSL, this url can be seen easily using any traffic monitoring tools, then, an attacker can get the link before user and reset the password.
One way to prevent this is to use fragment identifier
(#
) after url such as:
example.com/password#code=%CODE%
Then using:
<script>
var securykey = "<?php echo $_SESSION['securykey']; ?>";//random secure key
var hash = encrypt(window.location.hash.substring(1)+"|count="+securykey );
window.location = "example.com/password?code=hash"; //hash encryped
</script>
And then at Server side:
<?php
$code = decrypt($hash);
if($_SESSION['securykey'] == $securykey_from_user){
//its valid
}
?>
Dose above technique is strong? and shall we use fragment identifier even for TLS/SSL?
UPDATE:
- I didn't used my encryption. Sorry for mentioning AES it was not AES but openSSL using JavaScript.
- Google Also implemented HTML Fragment identifier! example:https://www.google.iq/#newwindow=1&safe=active&q=security.stack+exchange
- jsencrypt: is the library that I used in client side. https://github.com/travist/jsencrypt and then I used PHP openssl to decrypt it at server-side.
Source Code demo:
- javaScript: https://jsfiddle.net/da7jmxnu/
- PHP:
<?php
$config = array(
"digest_alg" => "sha512",
"private_key_bits" => 4096,
"private_key_type" => OPENSSL_KEYTYPE_RSA,
);
$res = openssl_pkey_new($config);
//$privKey = key saved in google cloud and accessed with https using curl
openssl_pkey_export($res, $privKey);
// Extract the public key from $res to $pubKey
$pubKey = openssl_pkey_get_details($res);
$pubKey = $pubKey["key"];
$data = 'plaintext data goes here';//$_POST['data']
// Encrypt the data to $encrypted using the public key
openssl_public_encrypt($data, $encrypted, $pubKey);
// Decrypt the data using the private key and store the results in $decrypted
openssl_private_decrypt($encrypted, $decrypted, $privKey);
?>