hi guys i`m making a project , i will paint the all picture for you. i have to create a server that send a serialized object to another client but this stream must be encrypted using a Cipher class but i just cant do this ... i will send a test code only but You will get the idea from it
A cipher is either initialized to encrypt or decrypt, not both. Therefore, you'll need two ciphers - one for encrypting and one for decrypting. You'll use the decrypt cipher in getInputStream() since you'll decrypt the data you've read, and use the encrypt cipher in getOutputStream() since you'll encrypt the data you're going to send.
This even allows for asymmetric encryption: the ciphers used for encrypting and decrypting can be totally different. This way, if you send the same data back, it will look different for anyone intercepting the data packets. Just make sure that the socket's encrypt cipher matches the server socket's decrypt cipher and vice versa.
Of course using the same cipher (except one for encrypting, the other for decrypting) will make sure there will be no bugs due to incorrect linking of the ciphers.
You can also write a wrapper around the ciphers, that can both encrypt and decrypt, and then either return encryption and decryption ciphers, or methods to wrap an input stream into a CipherInputStream and an output stream into a CipherOutputStream.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com