Git Product home page Git Product logo

Comments (5)

matlik avatar matlik commented on August 15, 2024 4

Try calling message.saveChanges() after signing.

from java-utils-mail-smime.

matlik avatar matlik commented on August 15, 2024 1

If you are referring to the ability to specify the encryption algorithm, I do have a fork that I will be pushing my changes to soon. You can see it at https://github.com/vnomics/java-utils-mail-smime under the variable-encryption-algorithms branch once I've pushed it.

As for the problem I was having with the text attachment, this is an example snippet of how to make the canonicalization safe for the inbound email message:

    BodyPart attachmentBody = new MimeBodyPart();
    attachmentBody.setDataHandler(new DataHandler(new ByteArrayDataSource(attachment, MediaType.TEXT_PLAIN_VALUE)));
    attachmentBody.setHeader( "Content-Transfer-Encoding", "base64" );
    attachmentBody.setFileName(attachmentName);
    multipart.addBodyPart(attachmentBody);

Setting the Content-Transfer-Encoding after setting the DataHandler resulted in the rendered email body containing Base64 output wrapped every 76 characters and delimited with "\r\n".

from java-utils-mail-smime.

l-O-O-l avatar l-O-O-l commented on August 15, 2024

@matlik Thanks very much for your post. i was using this library and having some strange behavior and though it was just my own problem.

Is it possible to publish your work and I could sync it.

Very much appreciate.

from java-utils-mail-smime.

l-O-O-l avatar l-O-O-l commented on August 15, 2024

@matlik you are the life saver. I have the encryption part working as expected now. But looks like still have issue with sign. i have a simple sign function that to send out email but looks like not work as expected:

		String from ="[email protected]", to="[email protected]", subject = "sbj", body="body";		
		javax.mail.Session mailSession = javax.mail.Session.getInstance(new Properties(), null);
		MimeMessage message = new MimeMessage(mailSession);
		message.setFrom(new InternetAddress(from));
		message.setRecipient(RecipientType.TO, new InternetAddress(to));
		message.setSubject(subject);
//		message.setContent(body, "text/plain; charset=utf-8"); // neither works.
		message.setText(body);
		System.out.println(SmimeUtil.getStatus(message));
		SmimeKey privateKey = getSmimeKey();
		message = SmimeUtil.sign(mailSession, message, privateKey);
		System.out.println(SmimeUtil.getStatus(message));
		System.out.println("-----------------");

And result

NEITHER
NEITHER
-----------------

I added JCE to JDK, and used the certificate that is generated from COMODO. Because the Encryption works, I think the SmimeKey should be generated right. But just did not figure out why the sign fails.

from java-utils-mail-smime.

l-O-O-l avatar l-O-O-l commented on August 15, 2024

Another observation:

I need to do following to get signed message sent out

	msg = SmimeUtil.sign(mailSession, msg, getSmimeKey());
	msg.setContent((Multipart) msg.getContent());
	msg.saveChanges();

Otherwise, I will get

	java.io.IOException: "text/plain" DataContentHandler requires String object, was given object of type class javax.mail.internet.MimeMultipart
	at javax.mail.Transport.send0(Transport.java:218)
	at javax.mail.Transport.send(Transport.java:80)

The https://github.com/vnomics/java-utils-mail-smime version handled it way much better. Hope those change would be push to maven.

from java-utils-mail-smime.

Related Issues (5)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.