|
From: <kc...@us...> - 2003-07-17 08:08:19
|
Update of /cvsroot/ebxmlms/ebxmlms/src/hk/hku/cecid/phoenix/pki
In directory sc8-pr-cvs1:/tmp/cvs-serv19796/src/hk/hku/cecid/phoenix/pki
Modified Files:
Tag: b0931
SMIMEEncrypter.java
Log Message:
modified s/mime encryption/decryption calling mechanism to suit ebmail usage
Index: SMIMEEncrypter.java
===================================================================
RCS file: /cvsroot/ebxmlms/ebxmlms/src/hk/hku/cecid/phoenix/pki/SMIMEEncrypter.java,v
retrieving revision 1.2.2.1
retrieving revision 1.2.2.2
diff -C2 -d -r1.2.2.1 -r1.2.2.2
*** SMIMEEncrypter.java 9 Apr 2003 08:41:44 -0000 1.2.2.1
--- SMIMEEncrypter.java 17 Jul 2003 08:08:13 -0000 1.2.2.2
***************
*** 100,103 ****
--- 100,107 ----
}
+ protected SMIMEEncrypter() {
+ initiate();
+ }
+
/**
The application should use this method to get a instance of SMIMEEncrypter
***************
*** 117,120 ****
--- 121,135 ----
}
+ public static SMIMEEncrypter getInstance() {
+ if (instance == null) {
+ synchronized(SMIMEEncrypter.class) {
+ if (instance == null) {
+ instance = new SMIMEEncrypter();
+ }
+ }
+ }
+ return instance;
+ }
+
/**
Create a encrypted MimeBodyPart.
***************
*** 131,136 ****
CertificateEncodingException {
try {
SMIMEEncryptedGenerator generator = new SMIMEEncryptedGenerator();
! generator.addKeyTransRecipient(getCertificate(alias));
generator.setContent(mimeMessage, session);
generator.setContentEncryptionAlgorithm(SMIMEEncryptedGenerator.
--- 146,165 ----
CertificateEncodingException {
try {
+ return createEncryptedMimeMessage(
+ getCertificate(alias), mimeMessage, session);
+ }
+ catch (Exception e) {
+ throw new SMIMEException("Cannot generate the encrypted " +
+ "MimeMessage", e);
+ }
+ }
+
+ public MimeMessage createEncryptedMimeMessage(
+ java.security.cert.Certificate cert, MimeMessage mimeMessage,
+ Session session) throws SMIMEException, KeyStoreException,
+ CertificateEncodingException {
+ try {
SMIMEEncryptedGenerator generator = new SMIMEEncryptedGenerator();
! generator.addKeyTransRecipient(convertCert(cert));
generator.setContent(mimeMessage, session);
generator.setContentEncryptionAlgorithm(SMIMEEncryptedGenerator.
***************
*** 162,169 ****
implementation of Certificate
*/
! private java.security.cert.X509Certificate getCertificate(String alias)
throws KeyStoreException, CertificateEncodingException, CertificateException
{
! java.security.cert.Certificate cert = compositeKs.getCertificate(alias);
/*
We need to firsly get the encoded form of the certificate and then
--- 191,198 ----
implementation of Certificate
*/
! private java.security.cert.Certificate getCertificate(String alias)
throws KeyStoreException, CertificateEncodingException, CertificateException
{
! return compositeKs.getCertificate(alias);
/*
We need to firsly get the encoded form of the certificate and then
***************
*** 172,175 ****
--- 201,208 ----
own certificate implementation!
*/
+ }
+
+ private java.security.cert.X509Certificate convertCert(
+ java.security.cert.Certificate cert) throws CertificateException {
JDKX509CertificateFactory certFactory = new JDKX509CertificateFactory();
return (java.security.cert.X509Certificate) certFactory.
|