PROBLEM WITH SMIME org.bouncycastle.mail.smime.examples.SendSignedAndEncryptedMail

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

PROBLEM WITH SMIME org.bouncycastle.mail.smime.examples.SendSignedAndEncryptedMail

Manuela Vergerio
Messaggio

--------------------------------------------------------------

From: Manuela Vergerio <[hidden email]>

To: [hidden email]

Subject: PROBLEM WITH SMIME org.bouncycastle.mail.smime.examples.SendSignedAndEncryptedMail

Hi,

I need your HELP.

I'm trying to SMIME encrypt a Mail message using a slightly altered org.bouncycastle.mail.smime.examples.SendSignedAndEncryptedMail.

My parameters are:

1) My PKCS12 file (*.p12) with its complete path
2) The password to open my PKCS12 file
3) my smtp server
4) e-mail address

For the alias I've got it by adding these lines at the original code:

/* Open the keystore */
KeyStore keystore = KeyStore.getInstance("PKCS12");
keystore.load(new FileInputStream(args[0]), args[1].toCharArray());

Enumeration enume = keystore.aliases();
for (; enume.hasMoreElements(); )
{
alias = (String)enume.nextElement();
}

Certificate[] chain = keystore.getCertificateChain(alias);

/* Get the private key to sign the message with */
PrivateKey privateKey = (PrivateKey) keystore.getKey(alias, args[1].toCharArray());

I've got this exception

java.security.InvalidKeyException: Illegal key size or default parameters
at javax.crypto.Cipher.a(DashoA12275)
at javax.crypto.Cipher.init(DashoA12275)
at javax.crypto.Cipher.init(DashoA12275)
at org.bouncycastle.cms.CMSEnvelopedDataGenerator$RecipientInf.toRecipientInfo(CMSEnvelopedDataGenerator.java:197)
at org.bouncycastle.cms.CMSEnvelopedDataGenerator.generate(CMSEnvelopedDataGenerator.java:407)
at org.bouncycastle.cms.CMSEnvelopedDataGenerator.generate(CMSEnvelopedDataGenerator.java:450)
at org.bouncycastle.mail.smime.SMIMEEnvelopedGenerator.make(SMIMEEnvelopedGenerator.java:114)
at org.bouncycastle.mail.smime.SMIMEEnvelopedGenerator.generate(SMIMEEnvelopedGenerator.java:197)
at org.bouncycastle.mail.smime.examples.SendSignedAndEncryptedMail.main(SendSignedAndEncryptedMail.java:163)
org.bouncycastle.mail.smime.SMIMEException: key inappropriate for algorithm.
at org.bouncycastle.mail.smime.SMIMEEnvelopedGenerator.make(SMIMEEnvelopedGenerator.java:124)
at org.bouncycastle.mail.smime.SMIMEEnvelopedGenerator.generate(SMIMEEnvelopedGenerator.java:197)
at org.bouncycastle.mail.smime.examples.SendSignedAndEncryptedMail.main(SendSignedAndEncryptedMail.java:163)


I debug the code and I find that the problem is at this line in class CMSEnvelopedDataGenerator.java:
keyCipher.init(Cipher.ENCRYPT_MODE, pubKey);

How con I resolve this Exception???

I also say that I'm using Eclipse with JAVA SDK 1.5.0_04.

Thanks in advance.
Manuela

-------------------------------------------------------------