Java & PGP

Pigbenis

Molten Core Raider
679
279
First off I am no crypto master by any stretch of the means nor do I really care to be. I know with PGP I can generate a shared key and set a private key, and from there If I give someone my shared key they can use that to encrypt text for me. Now if they give me that encrypted text I can use my private key to decrypt it.

Also, I don't want to store the private passphrase on the system

I've been searching for tutorials for days and my head is literally spinning. I'd imagine the code would look something like this.
Am I close here? Can someone point me in the right direction?
 

Luthair

Lord Nagafen Raider
1,247
85
It doesn't appear that you use the key you generated when creating a shared key? (At least your call to getMySharedKey() doesn't pass the public key)

In pseudo code / logic:
Your friend's code:
To be honest I didn't know PGP had a Java wrapper, most people simply use the Java crypto libraries.
 

Pigbenis

Molten Core Raider
679
279
Bouncycastle is the goto library for crypto I guess. Weirdest library name everbouncycastle.org. With my pseudo code the whole first section of code is generating 1 thing - the public / shared key. I would set the passphrase for that public key manually. The passphrase is what I would use to decrypt any encrypted text given back to me when my public / shared key was used.

I guess the getMySharedKey() method should be more like getTheSharedKeyThatWasGivenToMe(). Does that make sense?

The term shared key is actually miss-leading, it's more like public key. You give out the public key to people to encrypt text for you. Once it's encrypted you use your pass phrase which you keep secret to decrypt the message.
 

Luthair

Lord Nagafen Raider
1,247
85
Sorry started to write something, forgot to finish then forgot to come back
wink.png
Bouncy Castle is popular as it was developed outside the US thus not subject to export restrictions.

The shared key is actually what you generate by mixing your private key with their public key. The pass-phrase is only used to decrypt your private key, not decrypt the message.