Reputation: 267270
The goal of this is not for security, but for obscurity so the casual user will not be able to determine what the email address is.
I don't want to display an email address in the URL like:
www.example.com/[email protected]
I would like to encrypt the email address, with the goal of:
- the encrypted text should be encodable to be in a querystring
- the length should be as short as possible
- should not be easily decryptable e.g. using md5
- I can decrypt the value back
Can someone suggest an ecryption algorith that would meet the above criteria?
Upvotes: -2
Views: 1536
Reputation: 1538
When you talk about encryption you would have bytes, and not characters. Bu you can encode those bytes as characters using Base64. For example:
import javax.xml.bind.DatatypeConverter;
// Encrypt if you really need to encrypt it
// I am assuming you have a method that receive a String, encrypt it and return the byte[] encrypted.
// If you don't know how to encrypt, just ask a new question about how to do it in Java.
byte[] b = encrypt( "[email protected]" );
String encoded = DatatypeConverter.printBase64Binary( b );
// Otherwise, just encode it
b = "email.example.com".getBytes(java.nio.charset.StandardCharsets.UTF_8);
encoded = DatatypeConverter.printBase64Binary( b );
Upvotes: 2
Reputation: 39
If your aim is not to deal with Security aspect of it then you can achieve it through Base64 encoding and decoding of String
final String encodedValue = new BASE64Encoder().encode("[email protected]".getBytes());
System.out.println("encodedValue = "+encodedValue );
final String decodedValue = new String(new BASE64Decoder().decodeBuffer(encodedValue));
System.out.println("decodedValue = "+decodedValue);
Upvotes: 1