I am pretty new to Java. I have a flat file where I have stored my password encrypted using GPG utility from Unix. Now, I want to read the file and get the password into a string before connecting to a system. I have read the post Getting GPG Decryption To Work In Java (Bouncy Castle) but I cant use the program as it gives me error to add @ before PGPSecretKey and to remove tokens etc. Basically I dont know where to put the java methods into my Project.
Below is my code:
package jcpx.oracle.apps.gpg;
import org.bouncycastle.apache.*;
import org.bouncycastle.apache.bzip2.*;
import org.bouncycastle.bcpg.*;
import org.bouncycastle.bcpg.attr.*;
import org.bouncycastle.bcpg.sig.*;
import org.bouncycastle.openpgp.*;
private PGPSecretKey readSecretKey(InputStream in) throws IOException, PGPException {
in = PGPUtil.getDecoderStream(in);
PGPSecretKeyRingCollection pgpSec = new PGPSecretKeyRingCollection(in,
        new BcKeyFingerprintCalculator());
PGPSecretKey key = null;
for (Iterator<PGPSecretKeyRing> it = pgpSec.getKeyRings(); key == null && it.hasNext();) {
    PGPSecretKeyRing kRing = it.next();
    for (Iterator<PGPSecretKey> it2 = kRing.getSecretKeys(); key == null
            && it2.hasNext();) {
        PGPSecretKey k = it2.next();
        if ((keyId == null) && k.isSigningKey()) {
            key = k;
        }
        if ((keyId != null)
                && (Long.valueOf(keyId, 16).longValue() == (k.getKeyID() & MASK))) {
            key = k;
        }
    }
}
if (key == null) {
    throw new IllegalArgumentException("Can't find encryption key"
            + (keyId != null ? " '" + keyId + "' " : " ") + "in key ring.");
}
return key;
}