Results 1 to 8 of 8
Like Tree3Likes
  • 2 Post By SurfMan
  • 1 Post By gimbal2

Thread: how to decrypt emails and attachments in java

  1. #1
    fynn is offline Member
    Join Date
    Jul 2014
    Posts
    5
    Rep Power
    0

    Default how to decrypt emails and attachments in java

    Hi People,

    Currently my java program is reading emails along with attachments from the mailing server. It works fine as long as the email and the attachments are "not" encrypted.

    The problem comes when the email and/or the attachment are encrypted.

    I need to extend my application so that it should be able to handle encrypted emails and attachments as well.

    I did some research and found out that for decrypting the contents i need the private key of the recipient email id and the digital signature of the sender?

    If my above understanding is correct, could someone please refer me to some reference java examples / snippets where i get some insight into the java api used to perform this?

    Many thanks in advance.

    fynn.

  2. #2
    SurfMan's Avatar
    SurfMan is online now Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    946
    Rep Power
    2

    Default Re: how to decrypt emails and attachments in java

    No, you do not need the private key of the sender. Nobody needs a private key from the sender. A private key is, as you would expect, private. If the message is encrypted, then it is most likely encrypted using your public key. Only your private key can then decrypt that, which is a good thing, since you (and probably the NSA) are the only one with access to the private key. This system is called asymmetric encryption. I do not have first hand experience wiht doing this in Java, but it should get you started.
    gimbal2 and akiraaisha like this.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2™ © 2013

  3. #3
    fynn is offline Member
    Join Date
    Jul 2014
    Posts
    5
    Rep Power
    0

    Default Re: how to decrypt emails and attachments in java

    Thanks SurfMan.

    What you wrote is exactly what i meant!

    Since I am the recipient of the encrypted email hence I need my own private key to decrypt it plus the certificate of the sender who used my public key to encrypt the email before sending it to me.

    I guess this is what you meant as well.

    Thanks

  4. #4
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,982
    Rep Power
    5

    Default Re: how to decrypt emails and attachments in java

    This kind of encryption is a process. It goes a little something like this:

    - You have the requirement that data sent to you is encrypted. You generate your private key
    - you get a client which needs to communicate with you. You generate a -public- key for that client based on your private key (and generally for that client alone)
    - the client sends you data, encrypting it with the public key
    - you decrypt it with your private key that matches the public key

    - you get another client, you generate a new public key for them
    - etc.

    You are turning it around. You get some encrypted data "so you need a private key". That's not how it works, you must already have it.
    milovan likes this.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  5. #5
    fynn is offline Member
    Join Date
    Jul 2014
    Posts
    5
    Rep Power
    0

    Default Re: how to decrypt emails and attachments in java

    Thanks for the workflow description.

    Lets for the sake of simplicity assume that I have a private key and i have already given my customer the public key. Now my customer sends me an email which he encrypted using the public key i gave him. The mail arrives on my smtp server and now i need to decrypt that using my java application.

    I can open the encrypted email using pki token in my outlook, but i need to access that email directly from our smtp server through a java application.

  6. #6
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,515
    Blog Entries
    7
    Rep Power
    20

    Default Re: how to decrypt emails and attachments in java

    Quote Originally Posted by fynn View Post
    Thanks for the workflow description.

    Lets for the sake of simplicity assume that I have a private key and i have already given my customer the public key. Now my customer sends me an email which he encrypted using the public key i gave him. The mail arrives on my smtp server and now i need to decrypt that using my java application.

    I can open the encrypted email using pki token in my outlook, but i need to access that email directly from our smtp server through a java application.
    You're mixing things up again. For receiving messages you should connect to an imap or pop server. An smtp server is for sending messages ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    fynn is offline Member
    Join Date
    Jul 2014
    Posts
    5
    Rep Power
    0

    Default Re: how to decrypt emails and attachments in java

    Quote Originally Posted by JosAH View Post
    You're mixing things up again. For receiving messages you should connect to an imap or pop server. An smtp server is for sending messages ...

    kind regards,

    Jos
    Oh sorry, you are right, Jos.

  8. #8
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,598
    Rep Power
    5

    Default Re: how to decrypt emails and attachments in java

    I do not believe it works that way. The public keys and private keys can be both be used to encrypt plain text and decrypt cipher text. So you publish your public key to the world. Then if I want to encrypt a message to someone, I use their public key to encrypt it. Only they can decrypt it with their private key. If I want to send a message for authentication (so they know it came from me), I create a digital signature with my private key. Then anyone can authenticate the signature with my public key to ensure it was sent from me.

    Regards,
    Jim
    Last edited by jim829; 07-27-2014 at 03:41 PM.
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

Similar Threads

  1. Replies: 0
    Last Post: 01-06-2014, 11:40 AM
  2. Replies: 0
    Last Post: 01-03-2014, 01:06 PM
  3. encrypt and decrypt in java
    By Ashwin94 in forum New To Java
    Replies: 7
    Last Post: 08-09-2013, 04:31 PM
  4. Replies: 0
    Last Post: 05-31-2012, 10:31 AM
  5. emails thru java
    By marco in forum Java Applets
    Replies: 1
    Last Post: 08-15-2007, 11:02 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •