How do you encode URL in Android ?
Encoding URL is very straightforward, simply call the encode method of the URL Encoder class on the String data that you want to encode.
try {
String url = "http://www.yoursite.com/blah";
String queryString = "param=1&value=2";
String encodedQueryString = URLEncoder.encode(queryString,"UTF-8");
String encodedQueryStringInBase64 = Base64.encodeToString(encodedQueryString, Base64.DEFAULT);
encodedUrl = url + "?" + encodedQueryStringInBase64;
Log.d("Enc URL: " + encodedurl);
}
catch (UnsupportedEncodingException e)
{
Log.e("Exception: " + e.getMessage());
}
First:
Choose an encoding (UTF-8 is generally a good choice)
Transmitting end:
Encode the string to bytes (e.g. text.getBytes(encodingName))
Encode the bytes to base64 using the Base64 class
Transmit the base64
Receiving end:
Receive the base64
Decode the base64 to bytes using the Base64 class
Decode the bytes to a string (e.g. new String(bytes, encodingName))
Why do I need Base64 encoding?
Base64 is an encoding scheme used to represent binary data in an ASCII format. This is useful when binary data needs to be sent over media that are usually designed to handle textual data. Concrete examples would be sending images in an XML file or in an email attachment.
How does Base64 encoding work?
Bytes forming the data are broken into buffers of 24 bits (3 bytes at a time). The resulting buffer of 3 bytes is then broken in 4 packs of 6 bits each. Those 6 bits form a number corresponding to the index in the character set supported by Base64 (A-Z, a-z, 0-9, + and /). If the number of bytes are not in numbers of three, then padding is used; == for 1 byte and = for 2 bytes.
Is Base64 secure and can it be used to encrypt or obfuscate my data?
Hell no! Base64 is not for encryption purposes and is not secure at all. It's an encoding mechanism, nothing more.
2.
Security with HTTPS and SSL
If you are not worried about your data being decrypted you can use your own crypt algorithmic, since most users will not know what are your doing with those Strings.
An better way to do that is POST these parameters through the message body, and not in the URL. And if available, use a SSL connection.
Security with HTTPS and SSL is common building block for encrypted communications between clients and servers
Refer below the link for more details
http://developer.android.com/training/articles/security-ssl.html
try {
String url = "http://www.yoursite.com/blah";
String queryString = "param=1&value=2";
String encodedQueryString = URLEncoder.encode(queryString,"UTF-8");
String encodedQueryStringInBase64 = Base64.encodeToString(encodedQueryString, Base64.DEFAULT);
encodedUrl = url + "?" + encodedQueryStringInBase64;
Log.d("Enc URL: " + encodedurl);
}
catch (UnsupportedEncodingException e)
{
Log.e("Exception: " + e.getMessage());
}
First:
Choose an encoding (UTF-8 is generally a good choice)
Transmitting end:
Encode the string to bytes (e.g. text.getBytes(encodingName))
Encode the bytes to base64 using the Base64 class
Transmit the base64
Receiving end:
Receive the base64
Decode the base64 to bytes using the Base64 class
Decode the bytes to a string (e.g. new String(bytes, encodingName))
Why do I need Base64 encoding?
Base64 is an encoding scheme used to represent binary data in an ASCII format. This is useful when binary data needs to be sent over media that are usually designed to handle textual data. Concrete examples would be sending images in an XML file or in an email attachment.
How does Base64 encoding work?
Bytes forming the data are broken into buffers of 24 bits (3 bytes at a time). The resulting buffer of 3 bytes is then broken in 4 packs of 6 bits each. Those 6 bits form a number corresponding to the index in the character set supported by Base64 (A-Z, a-z, 0-9, + and /). If the number of bytes are not in numbers of three, then padding is used; == for 1 byte and = for 2 bytes.
Is Base64 secure and can it be used to encrypt or obfuscate my data?
Hell no! Base64 is not for encryption purposes and is not secure at all. It's an encoding mechanism, nothing more.
2.
Security with HTTPS and SSL
If you are not worried about your data being decrypted you can use your own crypt algorithmic, since most users will not know what are your doing with those Strings.
An better way to do that is POST these parameters through the message body, and not in the URL. And if available, use a SSL connection.
Security with HTTPS and SSL is common building block for encrypted communications between clients and servers
Refer below the link for more details
http://developer.android.com/training/articles/security-ssl.html
Comments
Post a Comment