• Post Reply Bookmark Topic Watch Topic
  • New Topic

Read object error javax.crypto.BadPaddingException: Given final block not properly padded  RSS feed

 
M Menezes
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I've got a problem trying to read a file using

to save


Save ok! but in reading this return error :




Can someone help me?

thanks

mmenezes
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know a lot about cryptography, but you made this comment:

But you didn't save the key. Instead, you generated a new temporary key in the other method. Do you generate the same key in both methods? It seems to me that if you try to decrypt with a different key than the one you used to encrypt, then problems would occur.
 
M Menezes
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is it, how I generate the same key forever?
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You also made this comment:

What did you mean by that?
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how I generate the same key forever?

You can't regenerate the key, a random one is generated if you call generateKey() . But you can obtain and store the key by calling key.getEncoded(). Then you can use it later for decryption.
 
M Menezes
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So this code is not mine, so was wondering how I generate a key through a phrase
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You would construct a SecretKeySpec object with the byte[] that you saved during encryption.
 
M Menezes
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok, thank you all for your help

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!