|
From: Sunila L. <sun...@EP...> - 2004-02-12 21:53:47
|
Hello,
Compiling and running Encrypt.java by itself is not problem, works
excellent. But when I add it to my project, compiled with all the mentioned
jar files (cryptix-openpgp-provider.jar, cryptix-message-api.jar,
cryptix-pki-api.jar, certpath-compat-api, cryptix-jce-provider.jar,
cryptix-jce-api.jar), and run through Tomcat(running on jdk1.4 with no
jce.jar) I get this error:
Exception in Encrypt class java.lang.IllegalArgumentException: IJCE does not
support ciphers for which implPadding == true
Any help is appreciated.
Encrypt.Java code follows.............
import cryptix.message.EncryptedMessageBuilder;
import cryptix.message.KeyBundleMessage;
import cryptix.message.LiteralMessage;
import cryptix.message.LiteralMessageBuilder;
import cryptix.message.Message;
import cryptix.message.MessageException;
import cryptix.message.MessageFactory;
import cryptix.openpgp.PGPArmouredMessage;
import cryptix.pki.KeyBundle;
import cryptix.pki.KeyBundleException;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.util.Collection;
import java.io.PrintWriter;
/**
* Detailed example for encrypting a message.
* This example assumes that the GenerateAndWriteKey example has been run
first.
*
* @author Edwin Woudt <ed...@cr...>
* @version $Revision: 1.1 $
*/
public class Encrypt {
private PrintWriter out;
private String product_name;
private String provider_class;
private String version_string;
private int errorcode;
//Should cryptix.util.test.TestException be included for these exit values?
// COMPLETE_SUCCESS = 10;
// COMPLETE_FAILURE = 1;
private static final int INSTALLED = 10;
private static final int ALREADY_INSTALLED = 10; // for the time being
private static final int NOT_INSTALLED = 1;
static public String Encrypt_CCnumber(String in_configFile, String
in_message, String in_pkasc, String in_tempefile, String sessionID) {
String encodedStr = "";
//**********************************************************************
WritetoJavaSecurity x = new WritetoJavaSecurity(new PrintWriter(System.out,
true),"Cryptix", "cryptix.provider.Cryptix", "Cryptix V3", sessionID);
x.run(in_configFile);
// Dynamically register both the Cryptix JCE and Cryptix OpenPGP
// providers.
//**********************************************************************
java.security.Security.addProvider(
new cryptix.jce.provider.CryptixCrypto() );
java.security.Security.addProvider(
new cryptix.openpgp.provider.CryptixOpenPGP() );
//**********************************************************************
// First read the key.
//**********************************************************************
KeyBundle bundle = null;
try {
UtilitiesBean.WriteToLogs(in_configFile, "Encrypt class "+in_pkasc,
sessionID);
FileInputStream in = new FileInputStream(in_pkasc);//"bob-public.pgp.asc");
MessageFactory mf = MessageFactory.getInstance("OpenPGP");
Collection msgs = mf.generateMessages(in);
KeyBundleMessage kbm = (KeyBundleMessage)msgs.iterator().next();
bundle = kbm.getKeyBundle();
in.close();
System.out.println("test3");
} catch (IOException ioe) {
UtilitiesBean.WriteToLogs(in_configFile, "IOException... You did remember to
run the "+
"GenerateAndWriteKey example first, right?", sessionID);
ioe.printStackTrace();
//System.exit(-1);
} catch (NoSuchAlgorithmException nsae) {
UtilitiesBean.WriteToLogs(in_configFile, "Cannot find the OpenPGP
MessageFactory. "+
"This usually means that the Cryptix OpenPGP provider is not "+
"installed correctly.",sessionID);
nsae.printStackTrace();
//System.exit(-1);
/* } catch (MessageException me) {
UtilitiesBean.WriteToLogs(in_configFile, "Reading keybundle
failed.",sessionID);
me.printStackTrace();
//System.exit(-1);
*/
} catch (Exception e) {
UtilitiesBean.WriteToLogs(in_configFile, "Exception in Encrypt class
"+e.toString(),sessionID);
System.out.println("Exception in Encrypt class "+e.toString());
//e.printStackTrace();
//System.exit(-1);
}
//**********************************************************************
// Build the literal message.
//**********************************************************************
LiteralMessage litmsg = null;
try {
String msg = in_message;//"This is a test message.\n" +"This is another
line.\n";
LiteralMessageBuilder lmb = LiteralMessageBuilder.getInstance("OpenPGP");
lmb.init(msg);
litmsg = (LiteralMessage)lmb.build();
} catch (NoSuchAlgorithmException nsae) {
UtilitiesBean.WriteToLogs(in_configFile, "Cannot find the OpenPGP
LiteralMessageBuilder."+
" This usually means that the Cryptix OpenPGP provider is not "+
"installed correctly.", sessionID);
nsae.printStackTrace();
//System.exit(-1);
} catch (MessageException me) {
UtilitiesBean.WriteToLogs(in_configFile, "Creating the literal message
failed.",sessionID);
me.printStackTrace();
//System.exit(-1);
}
System.out.println("test4444444444444");
//**********************************************************************
// Encrypt the message.
//**********************************************************************
Message msg = null;
try {
EncryptedMessageBuilder emb =
EncryptedMessageBuilder.getInstance("OpenPGP");
emb.init(litmsg);
emb.addRecipient(bundle);
msg = emb.build();
} catch (NoSuchAlgorithmException nsae) {
UtilitiesBean.WriteToLogs(in_configFile, "Cannot find the OpenPGP "+
"EncryptedMessageBuilder. "+
"This usually means that the Cryptix OpenPGP provider is not "+
"installed correctly.",sessionID);
nsae.printStackTrace();
//System.exit(-1);
} catch (MessageException me) {
UtilitiesBean.WriteToLogs(in_configFile, "Creating the encrypted message
failed.",sessionID);
me.printStackTrace();
// System.exit(-1);
}
System.out.println("msg == "+msg);
//**********************************************************************
// Armour the message and write it to disk
//**********************************************************************
try {
PGPArmouredMessage armoured;
armoured = new PGPArmouredMessage(msg);
FileOutputStream out = new FileOutputStream(in_tempefile, true);
out.write(armoured.getEncoded());
out.write("\r\n".getBytes());
encodedStr = armoured.getEncodedString();
out.close();
} catch (MessageException me) {
UtilitiesBean.WriteToLogs(in_configFile, "Writing the encrypted message
failed.",sessionID);
me.printStackTrace();
//System.exit(-1);
} catch (IOException ioe) {
UtilitiesBean.WriteToLogs(in_configFile, "Writing the encrypted message
failed.",sessionID);
ioe.printStackTrace();
//System.exit(-1);
}
encodedStr = "test";
return encodedStr;
}
}
|