passing encrypted data in url
Moderator: General Moderators
-
hessodreamy
- Forum Commoner
- Posts: 58
- Joined: Wed Apr 20, 2005 8:11 am
passing encrypted data in url
I know it sounds simple but I'm trying to pass encrypted data in a url, which i can later decrypt . I've been sniffing around the various encryption functions but it seems to me that the output would be a string that wouldn't legally fit into a url. Can anyone suggest a function to use?
-
hessodreamy
- Forum Commoner
- Posts: 58
- Joined: Wed Apr 20, 2005 8:11 am
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
- tecktalkcm0391
- DevNet Resident
- Posts: 1030
- Joined: Fri May 26, 2006 9:25 am
- Location: Florida
Here is what you can do:
Hope this works.
Code: Select all
<?php
// ---
// Code for First Page
// ---
// Variable to be encrypted and sent:
$text = "Hello";
// Encryption
// You can replace 8660281B6051D071D94B5B230549F9DC851566DC
// with any key you want just make sure to change it on the second page's key
$gpg = new gnupg();
$gpg -> addencryptkey("8660281B6051D071D94B5B230549F9DC851566DC");
$encypted_text = $gpg -> encrypt("$text");
// Encode for sending.
$send_string = 'encryptedtext=' . urlencode($encrypted_text) . '';
// Now just make it so it sends the codes
?>Code: Select all
<?php
// ---
// Code for Second Page
// ---
// Variable to be decrypted from send:
$recieved_text= $_GET['variable'];
//Decode URL
$recieved_text = urldecode($recieved_text);
//Decryption
// Make sure the 8660281B6051D071D94B5B230549F9DC851566DC
// matched the key on the first page // Leave test the same, or you can change it to anything.
$gpg = new gnupg();
$gpg -> adddecryptkey("8660281B6051D071D94B5B230549F9DC851566DC","test");
$text = $gpg -> decrypt($recieved_text);
// Decoded variable
$text = $text;
?>Hope this works.
-
hessodreamy
- Forum Commoner
- Posts: 58
- Joined: Wed Apr 20, 2005 8:11 am
I'm currently using a class (and have used other methods) based on the mcrypt function.
It all works very well but seems... messy.
The encrypted output is all kinds of crazy characters. As I'm putting the encrypted data in the url I'm using urlencode. So the query string is pretty long and looks messy.
I understand that encryption using only alphanumeric characters is less secure, but is there a method which gives alphanumerics?
I mean, I've seen lots of encoded stuff passed in urls in my time, but nothing that looked as messy as what I had.
background...
Apart from generally striving to understand encryption methods, the problem I'm currently working on is simply encrypting an email address to be used in a link from an email. I get it into my head that some people will object to their personal info being passed, so i'm just trying to obfucate that. In short, in this case maximum security isn't a massive priority, though I would like to understand things in case it was a priority.
It all works very well but seems... messy.
The encrypted output is all kinds of crazy characters. As I'm putting the encrypted data in the url I'm using urlencode. So the query string is pretty long and looks messy.
I understand that encryption using only alphanumeric characters is less secure, but is there a method which gives alphanumerics?
I mean, I've seen lots of encoded stuff passed in urls in my time, but nothing that looked as messy as what I had.
background...
Apart from generally striving to understand encryption methods, the problem I'm currently working on is simply encrypting an email address to be used in a link from an email. I get it into my head that some people will object to their personal info being passed, so i'm just trying to obfucate that. In short, in this case maximum security isn't a massive priority, though I would like to understand things in case it was a priority.
-
hessodreamy
- Forum Commoner
- Posts: 58
- Joined: Wed Apr 20, 2005 8:11 am