Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/quite/humla-spongycastle.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Tyley <roberto.tyley@gmail.com>2014-07-15 01:38:01 +0400
committerRoberto Tyley <roberto.tyley@gmail.com>2014-07-26 11:23:17 +0400
commit7cb752aaf746dc0b473afeb9e892b7fbc12666c5 (patch)
treecc4f91ddc18332b5adbe82e3fcb040d976c90105 /pg/src/main/java/org/spongycastle/openpgp/examples/PubringDump.java
parent551830f8ea5177042af2c7dd1fc90888bc67387d (diff)
Execute become-spongy.sh
https://github.com/rtyley/spongycastle/blob/3040af/become-spongy.sh
Diffstat (limited to 'pg/src/main/java/org/spongycastle/openpgp/examples/PubringDump.java')
-rw-r--r--pg/src/main/java/org/spongycastle/openpgp/examples/PubringDump.java100
1 files changed, 100 insertions, 0 deletions
diff --git a/pg/src/main/java/org/spongycastle/openpgp/examples/PubringDump.java b/pg/src/main/java/org/spongycastle/openpgp/examples/PubringDump.java
new file mode 100644
index 00000000..de565b96
--- /dev/null
+++ b/pg/src/main/java/org/spongycastle/openpgp/examples/PubringDump.java
@@ -0,0 +1,100 @@
+package org.spongycastle.openpgp.examples;
+
+import java.io.FileInputStream;
+import java.security.Security;
+import java.util.Iterator;
+
+import org.spongycastle.bcpg.PublicKeyAlgorithmTags;
+import org.spongycastle.jce.provider.BouncyCastleProvider;
+import org.spongycastle.openpgp.PGPPublicKey;
+import org.spongycastle.openpgp.PGPPublicKeyRing;
+import org.spongycastle.openpgp.PGPPublicKeyRingCollection;
+import org.spongycastle.openpgp.PGPUtil;
+import org.spongycastle.openpgp.operator.jcajce.JcaKeyFingerprintCalculator;
+import org.spongycastle.util.encoders.Hex;
+
+/**
+ * Basic class which just lists the contents of the public key file passed
+ * as an argument. If the file contains more than one "key ring" they are
+ * listed in the order found.
+ */
+public class PubringDump
+{
+ public static String getAlgorithm(
+ int algId)
+ {
+ switch (algId)
+ {
+ case PublicKeyAlgorithmTags.RSA_GENERAL:
+ return "RSA_GENERAL";
+ case PublicKeyAlgorithmTags.RSA_ENCRYPT:
+ return "RSA_ENCRYPT";
+ case PublicKeyAlgorithmTags.RSA_SIGN:
+ return "RSA_SIGN";
+ case PublicKeyAlgorithmTags.ELGAMAL_ENCRYPT:
+ return "ELGAMAL_ENCRYPT";
+ case PublicKeyAlgorithmTags.DSA:
+ return "DSA";
+ case PublicKeyAlgorithmTags.EC:
+ return "EC";
+ case PublicKeyAlgorithmTags.ECDSA:
+ return "ECDSA";
+ case PublicKeyAlgorithmTags.ELGAMAL_GENERAL:
+ return "ELGAMAL_GENERAL";
+ case PublicKeyAlgorithmTags.DIFFIE_HELLMAN:
+ return "DIFFIE_HELLMAN";
+ }
+
+ return "unknown";
+ }
+
+ public static void main(String[] args)
+ throws Exception
+ {
+ Security.addProvider(new BouncyCastleProvider());
+
+ PGPUtil.setDefaultProvider("SC");
+
+ //
+ // Read the public key rings
+ //
+ PGPPublicKeyRingCollection pubRings = new PGPPublicKeyRingCollection(
+ PGPUtil.getDecoderStream(new FileInputStream(args[0])), new JcaKeyFingerprintCalculator());
+
+ Iterator rIt = pubRings.getKeyRings();
+
+ while (rIt.hasNext())
+ {
+ PGPPublicKeyRing pgpPub = (PGPPublicKeyRing)rIt.next();
+
+ try
+ {
+ pgpPub.getPublicKey();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ continue;
+ }
+
+ Iterator it = pgpPub.getPublicKeys();
+ boolean first = true;
+ while (it.hasNext())
+ {
+ PGPPublicKey pgpKey = (PGPPublicKey)it.next();
+
+ if (first)
+ {
+ System.out.println("Key ID: " + Long.toHexString(pgpKey.getKeyID()));
+ first = false;
+ }
+ else
+ {
+ System.out.println("Key ID: " + Long.toHexString(pgpKey.getKeyID()) + " (subkey)");
+ }
+ System.out.println(" Algorithm: " + getAlgorithm(pgpKey.getAlgorithm()));
+ System.out.println(" Fingerprint: " + new String(Hex.encode(pgpKey.getFingerprint())));
+ }
+ }
+ }
+}