java cryptography

P

polaris

hi all
I have a program to encrypt/decrypt a file using existing secret key
and it works good. I got a key from a friend and an encrypted file to
decrypt it but the program throws this exception:

java.io.StreamCorruptedException: invalid stream header: 87449FAA
Exception in thread "main" java.security.InvalidKeyException: No
installed provider supports this key: (null)

this is my code:

try
{
//throws exception here
ObjectInputStream in = new ObjectInputStream(new
FileInputStream("key.dat"));
key = (SecretKey)in.readObject();
byte[] raw = key.getEncoded();
skeySpec = new SecretKeySpec(raw, "AES");
in.close();
}
catch (Exception e)
{
System.out.println(e);
}

//creating of Cipher
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.DECRYPT_MODE, skeySpec);
 
A

Arne Vajhøj

polaris said:
I have a program to encrypt/decrypt a file using existing secret key
and it works good. I got a key from a friend and an encrypted file to
decrypt it but the program throws this exception:

java.io.StreamCorruptedException: invalid stream header: 87449FAA
Exception in thread "main" java.security.InvalidKeyException: No
installed provider supports this key: (null)
//throws exception here
ObjectInputStream in = new ObjectInputStream(new
FileInputStream("key.dat"));
key = (SecretKey)in.readObject();
byte[] raw = key.getEncoded();
skeySpec = new SecretKeySpec(raw, "AES");
in.close();

Sounds to me as if readObject is not reading the bytes
properly.

Check the content of raw.

Arne
 
R

Roedy Green

java.io.StreamCorruptedException: invalid stream header: 87449FAA
Exception in thread "main" java.security.InvalidKeyException: No
installed provider supports this key: (null)

This is a bit of a long shot.

You might try instantiating the provider before you do the readObject.
Also make sure the JVM and JCE code on both ends match.

It may be only the JCE instantiator can find the implementing classes,
not the usual classload mechanism.

Alternatively, make sure the JCE implementation classes are on the
classpath.


..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top