Results 1 to 1 of 1
Thread: Cryptography
- 01-28-2012, 04:50 PM #1
Member
- Join Date
- Jan 2012
- Posts
- 1
- Rep Power
- 0
Cryptography
Hello,
Im currently writting one client-server application and I got stuck with crypting object that will be send throught network.
Here is my class dedicated to encrypting and decrypting:
What my problem is that SealedObject accept Object that implements Serializable and Cipher. As I wanna make these two function universal to all object that I will pass throught network, I need way to work it with Object as global.Java Code:public class Security { public static Object encrypt(Object obj){ SealedObject so = null; try { Cipher cp = Cipher.getInstance("DES"); cp.init(Cipher.ENCRYPT_MODE, getKey()); so = new SealedObject(obj, cp); } catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException e) { e.printStackTrace(); } return so; } public static Object decrypt(Object obj){ Object o = null; try { Cipher cp = Cipher.getInstance("DES"); cp.init(Cipher.DECRYPT_MODE, getKey()); o = ((SealedObject)obj).getObject(cp); } catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | ClassNotFoundException | IllegalBlockSizeException | BadPaddingException | IOException e) { e.printStackTrace(); } return o; } private static SecretKey getKey() throws NoSuchAlgorithmException{ KeyGenerator kg = KeyGenerator.getInstance("DES"); kg.init(new SecureRandom("keyValue".getBytes())); return kg.generateKey(); } }
I think of rewrite these function as generic, but I don't know how to filter object by Interface they implements.
Any help on these, or maybe there is some better way to achive these?
Thanks,
Bizz
Similar Threads
-
Cryptography Efficiency
By joshdgreen in forum Advanced JavaReplies: 22Last Post: 10-29-2010, 09:16 AM -
java.util.jar and cryptography
By telltera in forum New To JavaReplies: 1Last Post: 09-30-2010, 08:54 AM -
Cryptography Problem (BadPaddingException)
By LStrike in forum Advanced JavaReplies: 5Last Post: 03-09-2010, 07:53 PM -
cryptography
By swathi palla in forum AWT / SwingReplies: 2Last Post: 02-19-2009, 01:51 AM -
Legion of the Bouncy Castle Java Cryptography API 1.37
By Jamie in forum Java SoftwareReplies: 0Last Post: 06-16-2007, 09:42 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks