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

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top