0

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

I want to encrypt a hyperlink ...

3
  • What exactly do you mean by "encrypt"? What do you want to do with the link? Commented Feb 27, 2010 at 15:19
  • example I have the following link : 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... Commented Feb 27, 2010 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 Commented Feb 27, 2010 at 15:45

3 Answers 3

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 .

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

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; 

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.