Skip to Main Content

Java Security

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

RSA PSS Signature scheme

843811Aug 30 2005 — edited Feb 28 2006
Hi,

I am working on digital signatures RSA. I have two issues/doubts :-D

1) In Java 1.5, the crypto specification talks abt API support for RSA PKCS using PKCS #1 v2.1 thru the PSS padding scheme for signatures - java.security.spec.PPSParameterSpec. So, how i understood it was, after i create signature object for RSA i have to use setParameter to set these PSSParameterSpec to my signature object. But when i run my code, i get the UnSupportedOperationException. Please help me in this regard.

The Exception message is

java.lang.UnsupportedOperationException
at java.security.SignatureSpi.engineSetParameter(SignatureSpi.java:306)
at java.security.Signature$Delegate.engineSetParameter(Signature.java:11
61)
at java.security.Signature.setParameter(Signature.java:794)
at rsapsSigning.main(rsapsSigning.java:22)

My source code for the same is:

public class rsapsSigning
{
public static void main(String a[])
{

try
{

String datafile = "C:\\old.txt";
PSSParameterSpec pss = PSSParameterSpec.DEFAULT;

Signature s = Signature.getInstance("SHA1withRSA");

/*initialise sugnature object with pss parameter for RSA*/
s.setParameter((AlgorithmParameterSpec)pss); //exception gets thrown at this point

KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
kpg.initialize(128); // 128 is the keysize.
KeyPair kp = kpg.generateKeyPair();
PublicKey pubk = kp.getPublic();
PrivateKey prvk = kp.getPrivate();

s.initSign(prvk);

FileInputStream fis = new FileInputStream(datafile);
byte[] dataBytes = new byte[1024];
int nread = fis.read(dataBytes);
while (nread > 0) {
s.update(dataBytes, 0, nread);
nread = fis.read(dataBytes);
};
byte[] sig = s.sign();

for(int i = 0;i <sig.length;i++)
{
System.out.println(sig);

}

}catch(Exception e)
{
e.printStackTrace();
}
}

}

2) One other method that i tried was, instead of using PSSParameterSpec class, while creating Signature object, crypto Spec of 1.5 talks abt the usage of "<digest>with<encryptionalgo>and<mgf>" in the getInstance() of Signature class. So going on these lines, i can as well give "SHA1withRSAandMGF1" which is precisely what has been described as the default value for RSA PSS. But when i give so directly, I get "NoSuchAlgorithmException". In fact, for a trial basis when i tried "MD5withSHA1andMGF1" (the example given in the crypto spec of 1.5) also, i get the same exception :-( :-(

java.security.NoSuchAlgorithmException: SHA1withRSAandMGF1 Signature not availab
le
at java.security.Signature.getInstance(Signature.java:208)
at pp.main(pp.java:18)

My code for this is:


public class pp
{
public static void main(String a[])
{

try
{

String datafile = "C:\\new.txt";

Signature s = Signature.getInstance("SHA1withRSAandMGF1"); //exception gets thrown here

System.out.println("SHA1withRSAandMGF1");
}
catch(Exception e)
{
e.printStackTrace();
}
}
}

I am sorry that my query seems so long. But i was just trying to tell all the cases that I have tried.

I would be grateful to any suggestions.

Best Rgds
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 28 2006
Added on Aug 30 2005
6 comments
4,366 views