Talk:Secret Key Cryptography TutorialFrom WikiJavaComments on Secret Key Cryptography Tutorial <comments /> key management? right, Yeah.. thanks I forgot to mention it. The key is generated new at each execution. This program is just an experiment but has no real practical use. To be of any use we would need to store the generated key somehow. For example in a file. --DonGiulio 20:12, 2 January 2009 (UTC) algorithms Can we apply any algorithms ( I tried with TwoFish2) on the same program. My trial with TwoFish2 failed saying 'Twofish2 KeyGenerator not available' Hanumesh --61.16.169.37 12:18, 13 January 2009 (UTC) re: Storing generated key Can I just ask if you could show an example of storing/retrieving the generated key. Also what happens is the encryption is executed creating a key, then a second instance is executed, will that over-ride the 1st instances key thus making anything encrypted by the 1st instance 'lost'? --199.196.51.119 17:45, 23 January 2009 (UTC) Sending the key Hi, Thanks for posting wonderful explanation, as I am relatively new to this concept, I need some more information. I need to send the key generated to the other user for him to decrypt the message. I would encrypt the key with his public key so that only he can decrypt it. My problem is I am not able to understand how can Key's object be passed to him, i.e. please describe any way in which I can send him key object or something from which he can generate the same key in which the message is encrypted. --114.143.51.7 04:45, 16 February 2009 (UTC) Find out the key? So it is a private key for both methods, right? Is this possible to find out the key if you know the message, encrypted message and the encrypt algorithm? --123.24.155.116 17:50, 16 February 2009 (UTC) Bob Zitelli said ... DonGuilio, Thank you for posting this example. It is very helpful. --Bob Zitelli 03:40, 18 May 2009 (PDT) Robo Hmmm, I've copied this class verbatim, but I just get an exception when I try to decrypt: "Input length must be multiple of 8 when decrypting with padded cipher"
Using Predefined Key Nice experiment. This might be helpful to some - to further the experiment, I found I could use a given key (therefore it's reusable) with the following code to get the key instead of your generateKey() method. //your key info, get them from wherever they're stored String key = "7777777777777777";//must be 16 long String iv = "8888888888888888";//must be 16 long SecretKeySpec keySpec = new SecretKeySpec(key.getBytes(), "DES");
IvParameterSpec ivSpec = new IvParameterSpec(iv.getBytes());
Then, doing it this way, you have to add the iv to the cipher init call eg. cipher.init(Cipher.ENCRYPT_MODE, keySpec, ivSpec); The rest is the same. I also used AES for the SecretKeySpec and AES/CBC/PKCS5Padding for the algorithm.
Interesting about the reusable keys. Hi, This is a wiki, and what you just mentioned is very interesting, why don't you post your code and make a full article with it? I would be real interested in seeing it. Thanks,
AES code... code with nice secret key stuff --AES 19:58, 14 April 2011 (PDT) Made new article out of your comment Hi, Thanks for posting your code, I took it away to give it more space on a new article, here: Secret key cryptography. I also took the occasion to review and reorganize the code copy pasted from this article so that it's more readable. Please pass me your name, so I can refer you as author too. Thanks,
Thanks for new article! Hi Don! Thanks for creating a new article for this and moving my code snippets to a new spot. Looks great, I just checked it against my demo JSP and everything matches up. In fact I think I'll make a login and add my JSP code up here as well next. I actually tried to comment there first but it wouldn't let me saying it's not accepting comments. Something people might want to know is that there is a very handy Java library called Jasypt ( http://www.jasypt.org/ ) that helps you do these sorts of things, symmetrical encryption and decryption, as well as hashing and hash checking like for passwords. It makes things a little easier, however you should still know how things work. Jasypt has good default behavior but can't prevent someone from making security mistakes. I've used it and it was fairly easy to adjust to, especially with the much reduced code required to use it! Once you have the above example code running and you understand it, something like Jasypt is a good next step. By the way, my name is Michael Katich. I did not post the "AES" comment in the related Tutorial page but I was the one with the "Using Predefined Key" post. --Thanks for new article! 12:25, 17 May 2011 (PDT) Thank you for Sharing with Us .. < AwSM! /> --Thank you for Sharing with Us .. 04:26, 21 June 2011 (PDT) Thank you Very helpful article --Thank you 05:09, 1 August 2011 (PDT) JohnBush Hello! Very good job(this site)! Thank you man. --JohnBush 13:29, 3 August 2011 (PDT) Very nice site! Very nice site! --Very nice site! 06:45, 3 September 2011 (PDT) |

You might want to mention that any data you encrypt with this and then store will be lost forever after the program terminates. It generates a new, random key each run of the program. You could use a PBE algorithm or introduce the KeyStore...
--209.191.15.3 19:16, 2 January 2009 (UTC)