Java + JSS - Cipher operation failed on token

Composer, ChatZilla and other Mozilla applications, along with Netscape, Galeon, K-Meleon and other products.
Locked
saurabhsule82
Posts: 2
Joined: May 14th, 2010, 4:36 am

Java + JSS - Cipher operation failed on token

Post by saurabhsule82 »

I am trying to use NSS+JSS as JCA in Java. I get the following exception:

Exception in thread "main" org.mozilla.jss.crypto.TokenRuntimeException: Cipher operation failed on token
at org.mozilla.jss.provider.javax.crypto.JSSCipherSpi.engineDoFinal(JSSCipherSpi.java:397)
at javax.crypto.Cipher.doFinal(DashoA12275)
at javax.crypto.CipherInputStream.close(DashoA12275)

I am on RHEL 5 with jdk 1.5.0_12

I have modified the java.security file to include the following entry:

security.provider.7=org.mozilla.jss.JSSProvider

I am able to encrypt a file using the above combination but when I try to decrypt the same file, I get the exception.

Any pointers of how can I make NSS+JSS work in JCA mode with Java?
saurabhsule82
Posts: 2
Joined: May 14th, 2010, 4:36 am

Re: Java + JSS - Cipher operation failed on token

Post by saurabhsule82 »

I was able to encrypt/decrypt files using NSS+JSS as JCA in Java.

Initially I was using CipherInputStream and CipherOutputStream as a wrapper over FileInputStream and FileOutputStream for encryption and decryption. It didn't work. I went through the example code for encryption and decryption posted on mozilla's site.

I based my solution on the same code and it worked very well. But now I am stuck with another problem. It worked only in non-FIPS mode.

When I enable the FIPS mode it starts giving error saying cannot 'unwrap the key'. This, as I understand, is basically because we need to wrap and unwrap keys before encryption/decryption according to FIPS specification. But I have not been able get this working properly.

What I would like to do is generate AES 128 bit key from a predefined text, use it to encrypt a file. Then later again generate the same key and decrypt the file. But then how to wrap/unwrap this key?
aiter
Posts: 2
Joined: August 1st, 2013, 6:31 am

Re: Java + JSS - Cipher operation failed on token

Post by aiter »

Hello Saurabhsule82,

I am working on doing encryption and decryption stuff using NSS+JSS using java application in FIPS mode. Looks like you got achieved and able to work with that. I have experience working with JCE provider but this is the first time i am using NSS.

need your help in working with that. Please respond with your suggestions.

Thank you,
Aiter
User avatar
LIMPET235
Moderator
Posts: 39936
Joined: October 19th, 2007, 1:53 am
Location: The South Coast of N.S.W. Oz.

Re: Java + JSS - Cipher operation failed on token

Post by LIMPET235 »

The last post was....."Posted Tue 18th May 2010."

I doubt whether anyone is still interested.

If you have a problem, start a new thread. Thank you.

Locking due to old age.
[Ancient Amateur Astronomer.]
Win-10-H/64 bit/500G SSD/16 Gig Ram/450Watt PSU/350WattUPS/Firefox-115.0.2/T-bird-115.3.2./SnagIt-v10.0.1/MWP-7.12.125.

(Always choose the "Custom" Install.)
Locked