RSA Key Spec problem

I basically got this code right from the Tutorial at:

http://java.sun.com/docs/books/tutorial/security1.2/apisign/enhancements.html

.

.

.

//"buf" is a byte array containing my RSA private key

java.security.spec.X509EncodedKeySpec spec =

new java.security.spec.X509EncodedKeySpec(buf);

java.security.KeyFactory key = java.security.KeyFactory.getInstance("RSA");

java.security.PrivateKey priv = key.generatePrivate(spec);

java.security.Signature sig = java.security.Signature.getInstance("RSA");

sig.initSign(priv);

.

.

.

It blows up at the line:

java.security.PrivateKey priv = key.generatePrivate(spec);

with the error:

java.security.spec.InvalidKeySpecException: Key spec not RSA.

What Key spec can I use that works with RSA? TIA!

[896 byte] By [samt1] at [2007-9-26 1:52:10]
# 1
Did you find the "simple" answer to your question?
amaz007 at 2007-6-29 3:01:32 > top of Java-index,Core,Core APIs...
# 2
generatePrivate() can only be used with PrivateKeySpecs such as PKCS8EncodedKeySpec... If you are going to use X509EncodedKeySpec you must be dealing with a Public Key so you would use generatePublic()...
floersh at 2007-6-29 3:01:32 > top of Java-index,Core,Core APIs...