Re: Java string encryption/decryption

On Sat, 22 Nov 2008 07:48:36 -0800 (PST), dj_uncas <djuncas@xxxxxxxxx>

If that doesn't work then show more code.

It didn't... I found that it isn't the Cipher that throws the
NoSuchAlgorithmException, but the KeyGenerator.getInstance(). My code
looks like this:

KeyGenerator kg = KeyGenerator.getInstance( "AES/CBC/PKCS5Padding" );
You need to read the Javadoc more carefully. The algorithms for
KeyGenerator.getInstance() are not the same as for
Cipher.getInstance() Key generation does not involve a mode or

KeyGenerator kg = KeyGenerator.getInstance( "AES" );

System.out.println( kg.getProvider().getName() );
SecretKey key = kg.generateKey();

Cipher c = Cipher.getInstance( "AES/CBC/PKCS5Padding" );
c.init( mode, key );

byte[] result = c.doFinal( input );

Are you retrieving the generated key?

AlgorithmParameters ap = c.getParameters();

Without it you will not be able to decrypt. The same key is needed on
the decrypting machine.

Can you spot something?