Cipher.wrap and unwrap problem
Hi,
I am starting on cryptography and tried to use Cipher for wrap and unwrap of key, but while unwrapping i get the exception - java.security.InvalidKeyException: The wrapped key is not padded correctly.
KeyGenerator and Cipher is created with algorithm as "DES". Parameters are not given. I encrypt a file and wrap the key and store in a file. In a sperate call, i try to decrypt the encrypted file, after unwrapping the encrypted key. Here I get the exception, while unwrapping.
To eliminate error in reading the key from file for unwrapping, I tried calling decrypt immediately after encrypt and all works fine (encrypting, wrapping, unwrap key from file and decrypting). The problem happens when i try to use it with another instance of the class or with a new JVM. I have no clue on how to debug this problem.
Can someone help me and enlighten on what I might possibly be doing wrong.
Stack trace.
at com.sun.crypto.provider.SunJCE_h.a(DashoA6275)
at com.sun.crypto.provider.DESCipher.engineUnwrap(DashoA6275)
at javax.crypto.Cipher.unwrap(DashoA12275)

