package pgp.services.keys; import com.wm.data.*; import com.wm.util.Values; import com.wm.app.b2b.server.Service; import com.wm.app.b2b.server.ServiceException; import java.util.Iterator; import org.bouncycastle.openpgp.PGPPrivateKey; import org.bouncycastle.openpgp.PGPPublicKey; import org.bouncycastle.openpgp.PGPPublicKeyRingCollection; import org.bouncycastle.openpgp.PGPSecretKey; import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.bouncycastle.openpgp.PGPSecretKeyRingCollection; import com.softwareag.pgp.PGPInit; import com.softwareag.pgp.PGPKeyReader; import com.wm.data.IData; import com.wm.data.IDataCursor; import com.wm.data.IDataFactory; import com.wm.data.IDataUtil; public final class readPrivateKeys_SVC { /** * The primary method for the Java service * * @param pipeline * The IData pipeline * @throws ServiceException */ public static final void readPrivateKeys(IData pipeline) throws ServiceException { // Get input IDataCursor pc = pipeline.getCursor(); String path = IDataUtil.getString(pc, "path"); String pasw = IDataUtil.getString(pc, "password"); IData data = IDataFactory.create(); PGPSecretKeyRingCollection ringSecret = null; PGPSecretKey keySecret = null; PGPPrivateKey keyPrivate = null; try { IDataCursor dc = data.getCursor(); ringSecret = PGPKeyReader.readSecretKeyRing(path); keySecret = PGPKeyReader.readSecretKey(path); IDataUtil.put(dc, "privateKeyRing", ringSecret); IDataUtil.put(dc, "privateKeyRingSize", ringSecret.size()); if (pasw != null) { keyPrivate = PGPKeyReader.readPrivateKey(keySecret,pasw.toCharArray()); IDataUtil.put(dc, "privateKey", keyPrivate); IDataUtil.put(dc, "keyId", String.valueOf(keyPrivate.getKeyID())); IDataUtil.put(dc, "algorithm", keyPrivate.getKey().getAlgorithm()); IDataUtil.put(dc, "format", keyPrivate.getKey().getFormat()); IDataUtil.put(dc, "isSigningKey", String.valueOf(keySecret.isSigningKey())); IDataUtil.put(dc, "isMasterKey", String.valueOf(keySecret.isMasterKey())); } dc.destroy(); } catch (Exception e) { throw new RuntimeException("Unable to read private key file: " + e.getMessage()); } IDataUtil.put(pc, "privateKeyData", data); pc.destroy(); } // --- <> --- // --- <> --- /** * The service implementations given below are read-only and show only the * method definitions and not the complete implementation. */ public static final void listEncryptionAlgorithms(IData pipeline) throws ServiceException { } public static final void listKeyExchangeAlgorithms(IData pipeline) throws ServiceException { } public static final void listSignatureAlgorithms(IData pipeline) throws ServiceException { } public static final void readPublicKeys(IData pipeline) throws ServiceException { } final static readPrivateKeys_SVC _instance = new readPrivateKeys_SVC(); static readPrivateKeys_SVC _newInstance() { return new readPrivateKeys_SVC(); } static readPrivateKeys_SVC _cast(Object o) { return (readPrivateKeys_SVC)o; } }