public key encryption javax.crypto

Discussion in 'Java' started by Larry Grant, May 7, 2004.

  1. Larry Grant

    Larry Grant Guest

    My primary eperience with crypto is using PGP, but now I'd like to use
    crypto in a Java application. I've been wading therough the javadocs
    for the "javax.crypto" package, and I'm having a hard time finding any
    straightforward way to just perform basic public key encryption like
    PGP does. I've found references to ElGamal and Diffie-Hellman
    algorithms, but they seem to be all about "key agreements", not
    encryption.

    Is there anything in javax.crypto that will just let me generate key
    pairs and then perform encryptions to public keys and decryptions from
    private keys?
     
    Larry Grant, May 7, 2004
    #1
    1. Advertising

  2. Larry Grant wrote:

    > My primary eperience with crypto is using PGP, but now I'd like to use
    > crypto in a Java application. I've been wading therough the javadocs
    > for the "javax.crypto" package, and I'm having a hard time finding any
    > straightforward way to just perform basic public key encryption like
    > PGP does. I've found references to ElGamal and Diffie-Hellman
    > algorithms, but they seem to be all about "key agreements", not
    > encryption.
    >
    > Is there anything in javax.crypto that will just let me generate key
    > pairs and then perform encryptions to public keys and decryptions from
    > private keys?
     
    Michael Borgwardt, May 7, 2004
    #2
    1. Advertising

  3. Larry Grant wrote:

    > My primary eperience with crypto is using PGP, but now I'd like to use
    > crypto in a Java application. I've been wading therough the javadocs
    > for the "javax.crypto" package, and I'm having a hard time finding any
    > straightforward way to just perform basic public key encryption like
    > PGP does. I've found references to ElGamal and Diffie-Hellman
    > algorithms, but they seem to be all about "key agreements", not
    > encryption.
    >
    > Is there anything in javax.crypto that will just let me generate key
    > pairs and then perform encryptions to public keys and decryptions from
    > private keys?


    CipherInputStream and CipherOutputStream sounds promising to me...
     
    Michael Borgwardt, May 7, 2004
    #3
  4. Larry Grant

    Carl Howells Guest

    Larry Grant wrote:
    > My primary eperience with crypto is using PGP, but now I'd like to use
    > crypto in a Java application. I've been wading therough the javadocs
    > for the "javax.crypto" package, and I'm having a hard time finding any
    > straightforward way to just perform basic public key encryption like
    > PGP does. I've found references to ElGamal and Diffie-Hellman
    > algorithms, but they seem to be all about "key agreements", not
    > encryption.
    >
    > Is there anything in javax.crypto that will just let me generate key
    > pairs and then perform encryptions to public keys and decryptions from
    > private keys?


    Having done this recently:

    Kind of.

    javax.crypto and java.security provide an interface with which
    public-key encryption can be performed. However, they don't provide a
    default implementation of most algorithms, instead providing only the a
    common interface for provider to use.

    I ended up using bouncycastle <http://www.bouncycastle.org/> as the
    provider, using the javax.crypto and java.security interfaces.
     
    Carl Howells, May 7, 2004
    #4
  5. Larry Grant

    Larry Grant Guest

    Michael Borgwardt <> wrote in message news:<>...
    > Larry Grant wrote:
    > >
    > > Is there anything in javax.crypto that will just let me generate key
    > > pairs and then perform encryptions to public keys and decryptions from
    > > private keys?

    >
    > CipherInputStream and CipherOutputStream sounds promising to me...


    I'd seen those, but I thought they were only for symmetric-key (not
    public key) encryption. I'll take another look. Thanks.
     
    Larry Grant, May 7, 2004
    #5
  6. Larry Grant wrote:
    >>>Is there anything in javax.crypto that will just let me generate key
    >>>pairs and then perform encryptions to public keys and decryptions from
    >>>private keys?

    >>
    >>CipherInputStream and CipherOutputStream sounds promising to me...

    >
    >
    > I'd seen those, but I thought they were only for symmetric-key (not
    > public key) encryption. I'll take another look. Thanks.


    Note that PGP and all similar programs do NOT use public key cryprography on
    the actual content; they use it only to encrypt a session key which is then
    used with a symmetric-key algorithm.
     
    Michael Borgwardt, May 8, 2004
    #6
  7. Larry Grant

    Roedy Green Guest

    On Sat, 08 May 2004 02:29:09 +0200, Michael Borgwardt
    <> wrote or quoted :

    >Note that PGP and all similar programs do NOT use public key cryprography on
    >the actual content; they use it only to encrypt a session key which is then
    >used with a symmetric-key algorithm.


    To use these classes, you don't need to be aware of how it works under
    the covers. You just feed PGP keys and text and both ends and it does
    it thing.


    BouncyCastle is a JCE (Java Cryptographic Extension)-compatible
    library that also handles PGP. It is well regarded. The source is not
    well formatted or commented. The JavaDoc is sparce and inaccurate.

    You will want to download the BouncyCastle jars for:
    JCE Provider
    open PGP
    test examples
    Java Source for Open PGP

    Put the jars in your ext directory.

    Generating Keys

    Generate a binary private/public key with:

    java org.BouncyCastle.openpgp.examples.RSAKeyPairGenerator charlie
    "open sesame"

    The public and private keys will appear as pub.bpg, and secret.bpg.
    You can generate ascii *.asc ascii armoured file instead by using the
    -a option like this:

    java org.bouncycastle.openpgp.examples.RSAKeyPairGenerator -a charlie
    "open sesame"

    To generate variants look at the source code in bcpg-jdk14-122/src/
    org/bouncycastleopenpgp/examples/RSAKeyPairGenerator.java

    Signing A Binary File

    java org.bouncycastle.openpgp.examples.SignedFileProcessor -s
    anyfile.dat secret.bpg "open sesame"

    Resulting signed file will appear in anyfile.dat.bpg signed, but not
    encrypted.

    Verifying a Signed Binary File

    java org.bouncycastle.openpgp.examples.SignedFileProcessor -v
    anyfile.dat.bpg pub.bpg
    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
     
    Roedy Green, May 8, 2004
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Digby
    Replies:
    4
    Views:
    4,021
    Digby
    Oct 8, 2003
  2. ClaudiaE
    Replies:
    1
    Views:
    589
    Hans Granqvist
    Dec 3, 2003
  3. Replies:
    0
    Views:
    22,539
  4. Metruchio

    javax.crypto

    Metruchio, Feb 15, 2005, in forum: Java
    Replies:
    3
    Views:
    497
  5. david wolf
    Replies:
    3
    Views:
    19,410
    Spykar
    Apr 17, 2014
Loading...

Share This Page