Skip to Main Content

Java Security

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

problem with PBEWITHSHA1AND128BITAES-CBC-BC

843811Oct 19 2007 — edited Oct 19 2007
Hello

I need help.

I'm using BC provider and I want to encrypt/decrypt data with my password. I will use algoritm "PBEWITHSHA1AND192BITAES-CBC-BC"
I attach mysource code for initialization of Cipher:
byte[] salt = new byte[] { 0x7d, 0x60, 0x43, 0x5f, 0x02, (byte) 0xe9, (byte) 0xe0, (byte) 0xae };
      int iterationCount = 19;
      byte [] iv  = new byte[128];
      
      AlgorithmParameterSpec algSpec = new IvParameterSpec(iv);
      PBEKeySpec keySpec = new PBEKeySpec("palo".toCharArray(),salt,iterationCount);
      SecretKey key = SecretKeyFactory.getInstance("PBEWITHSHA1AND192BITAES-CBC-BC","BC").generateSecret(keySpec);
      Cipher cipher = Cipher.getInstance(key.getAlgorithm(),"BC");
      cipher.init(Cipher.ENCRYPT_MODE,key,algSpec);//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      //load data
      File f = new File("c:\\data");
      DataInputStream dis = new DataInputStream(new FileInputStream(f));
      byte [] data = new byte[(int)f.length()];
      dis.readFully(data);
      dis.close();
      cipher.update(data);
      byte [] encData = cipher.doFinal();
But I got follow exception online with initialization of Cipher:
java.security.InvalidKeyException: Illegal key size
	at javax.crypto.Cipher.a(DashoA12275)
	at javax.crypto.Cipher.init(DashoA12275)
	at javax.crypto.Cipher.init(DashoA12275)
	at pokus.Untitled1.generuj(Untitled1.java:225)
	at pokus.Sprav.main(Sprav.java:25)
I tried it with algorithm PBEWITHSHA1AND128BITAES-CBC-BC and work's fine.

can somebody tell me where is problem ?

Thanks
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 16 2007
Added on Oct 19 2007
1 comment
337 views