Encrypting an Object with DES

This example demonstrates how to encrypt a serializable object.
try { // Generate a temporary key. In practice, you would save this key. // See also Encrypting with DES Using a Pass Phrase. SecretKey key = KeyGenerator.getInstance("DES").generateKey(); // Prepare the encrypter Cipher ecipher = Cipher.getInstance("DES"); ecipher.init(Cipher.ENCRYPT_MODE, key); // Seal (encrypt) the object SealedObject so = new SealedObject(new MySecretClass(), ecipher); // Get the algorithm used to seal the object String algoName = so.getAlgorithm(); // DES // Prepare the decrypter Cipher dcipher = Cipher.getInstance("DES"); dcipher.init(Cipher.DECRYPT_MODE, key); // Unseal (decrypt) the class MySecretClass o = (MySecretClass)so.getObject(dcipher); } catch (java.io.IOException e) { } catch (ClassNotFoundException e) { } catch (javax.crypto.IllegalBlockSizeException e) { } catch (javax.crypto.BadPaddingException e) { } catch (javax.crypto.NoSuchPaddingException e) { } catch (java.security.NoSuchAlgorithmException e) { } catch (java.security.InvalidKeyException e) { } public class MySecretClass implements java.io.Serializable { String s = "the secret"; }

Comments

6 Apr 2010 - 10:02pm by atul khare (not verified)

please if nayone have a project on simple DES algorithm then please send it to me at any cost. i need it despirately,
my id is--> atul_khare@ymail.com

Post a comment

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image. Ignore spaces and be careful about upper and lower case.