Using example from Java Secuirty, get Exception

using the following example from professional Java Security to test my installation of jce and bouncycastle.

<code>

import java.security.*;

import javax.crypto.*;

/**

*SimpleExample.java

*

*This class creates a TripleDES key, encrypts some text,

*prints the ciphertext, then decrypts the text and

*prints that.

*

*It requires a JCE-compliant TripleDES engine, like Cryptix' JCE.

*/

public class SimpleExample

{

public static void main (String[] args)

throws Exception

{

if (args.length != 1) {

System.err.println("Usage: java SimpleExample text");

System.exit(1);

}

String text = args[0];

System.out.println("Generating a TripleDES key...");

// Create a TripleDES key

KeyGenerator keyGenerator = KeyGenerator.getInstance("TripleDES");

keyGenerator.init(168);// need to initialize with the keysize

Key key = keyGenerator.generateKey();

System.out.println("Done generating the key.");

// Create a cipher using that key to initialize it

Cipher cipher = Cipher.getInstance("TripleDES/ECB/PKCS5Padding");

cipher.init(Cipher.ENCRYPT_MODE, key);

byte[] plaintext = text.getBytes("UTF8");

// Print out the bytes of the plaintext

System.out.println("\nPlaintext: ");

for (int i=0;i<plaintext.length;i++) {

System.out.print(plaintext+" ");

}

// Perform the actual encryption

byte[] ciphertext = cipher.doFinal(plaintext);

// Print out the ciphertext

System.out.println("\n\nCiphertext: ");

for (int i=0;i<ciphertext.length;i++) {

System.out.print(ciphertext+" ");

}

// Re-initialize the cipher to decrypt mode

cipher.init(Cipher.DECRYPT_MODE, key);

// Perform the decryption

byte[] decryptedText = cipher.doFinal(ciphertext);

String output = new String(decryptedText,"UTF8");

System.out.println("\n\nDecrypted text: "+output);

}

}

></code>

it compiles fine but at runtime i get the folowing exception:

Exception in thread "main" java.lang.SecurityException: Unsupported keysize or algorithm parameters

at javax.crypto.Cipher.init(DashoA6275)

at SimpleExample.main(SimpleExample.java:35)

Anyone have any ideas about this.

running jdk 1.4 beta 3, jce packaged with it

(UK resident)

Thanks for any assistance

gandalfgrey

[2564 byte] By [gandalfgrey] at [2007-9-26 14:23:23]
# 1

Sorry for this post, i didnt realise but i needed unlimited instead of strong encryption to deal with the key size so had to download the policy files for unlimited encryption outside the US. The example then worked fine.

Hope this post may be of use to those not as fortunate as me in finding my answer.

caio thee olde wizard

gandalfgrey at 2007-7-2 16:04:09 > top of Java-index,Security,Cryptography...