What is the best way to encrypt an URL with parameters in Java?
相关问题
- “Zero out” sensitive String data in Swift
- High cost encryption but less cost decryption
- UrlEncodeUnicode and browser navigation errors
- Improve converting string to readable urls
- Jasper: error opening input stream from url
相关文章
- decrypt TLS 1.2 AES-GCM packet
- C# HttpClient.SendAsync always returns 404 but URL
- Decrypting EnvelopedCms with non-default Algorithm
- Prevent $anchorScroll from modifying the url
- How does a browser handle cookie with no path and
- C# AES Rijndael - detecting invalid passwords
- Base64URL decoding via JavaScript?
- Sanity check SSH public key? [closed]
Are you sure you don't mean URL encode?
Encoding is available through
java.net.URLEncoder.encode
.Unfortunatelly almost noting is simple in java :-) , for this simple and usual task I wasnt able to find a prepared library, I ended up writing this (this was the source):
}
It depends on your threat model. For example, if you want to protect the parameters sent by your Java app to your server from an attacker who has access to the communication channel, you should consider communicating with the server via TLS/SSL (i.e., HTTPS in your case) and the likes. If you want to protect the parameters from an attacker who has access to the machine where your Java client app runs, then you're in deeper trouble.
The only way to do this is to use SSL/TLS (https). If you use plain old HTTP, the URL will definitely be sent in the clear.
The standard way to encrypt HTTP traffic is to use SSL.
However, even over HTTPS, the URL and any parameters in it (i.e. a GET request) will be sent in the clear. You would need to use SSL and do a POST request to properly encrypt your data.As pointed out in the comments parameters will be encrypted no matter what HTTP method you use, as long as you use an SSL connection.
If you really can't use SSL, I'd suggest a pre-shared key approach and adding a random iv.
You can use any decent symmetric encryption method ex. AES using a pre-shared key you're communicating out of band (email, phone etc.).
Then you generate a random initialization vector and encrypt your string with this iv and the key. Finally you concatenate your cipher text and the iv and send this as your parameter. The iv can be communicated in the clear without any risk.