0

can anyone tell me how to encrypt and decrypt a URL string ?

I want to encrypt a hyperlink ...

redcoder
  • 97
  • 1
  • 2
  • 8
  • What exactly do you mean by "encrypt"? What do you want to do with the link? – Pekka Feb 27 '10 at 15:19
  • example I have the following link : http://localhost/waterwell/e_book.php?flnm8=New Folder\PhotoPlus Reg.txt I want to change the [New Folder\PhotoPlus Reg.txt] into something that is encrypted.. so that ppl won't see the actual path... – redcoder Feb 27 '10 at 15:23
  • i read the file direct from server directory..... what i want is something like this : The encrytped URL shows this: localhost/waterwell/e_book.php?flnm8=werf182hvd but when they click on the link, it will decrpt the werf182hvd convert to the actual filename which is New Folder\PhotoPlus Reg.txt – redcoder Feb 27 '10 at 15:45

3 Answers3

1

If you can use database,you could create a table to map a file to an id.

Create a 'mapping_table'

id - integer
file_location - string

Your URL would look something like localhost/waterwell/e_book.php?id=12 .

vsr
  • 3,138
  • 1
  • 19
  • 14
0

make links that return to your server with querystring GET params identifying the file. the server can then do echo file_get_contents() after you figure out which file from the inputs

In your example it's trivial. simply omit the portion of the url you don't want shown and fill it back in on the server.

Scott Evernden
  • 39,136
  • 15
  • 78
  • 84
0
    $confirmpassword = $_POST['confirmpassword'];
            $value_check = true;
            $ciphering = "AES-128-CTR";
            $options = 0; 
            $encryption_iv = '1234567891011121'; 
            $encryption_key = "GeeksforGeeks";
            $confirmpasswordencryption = openssl_encrypt($confirmpassword, $ciphering,$encryption_key, $options, $encryption_iv);  

$encryption = "pABqPJhobIMHzqai"
                                                        $ciphering = "AES-128-CTR";
                                                        $options = 0;
                                                        $decryption_iv = '1234567891011121'; 
  
// Store the decryption key 
$decryption_key = "GeeksforGeeks"; 
  
// Use openssl_decrypt() function to decrypt the data 
$decryption=openssl_decrypt ($encryption, $ciphering,  
        $decryption_key, $options, $decryption_iv); 
  
// Display the decrypted string 
echo "Decrypted String: " . $decryption; 
Maulik patel
  • 2,546
  • 2
  • 20
  • 26
  • **Security warning - the code above is using a static initialization vector (IV) that makes the complete encryption UNSECURE**. Kindly use a randomly generated iv that is prepended to the ciphertext, thanks. – Michael Fehr Dec 14 '20 at 08:57