Methods Summary |
---|
public void | addIdentity(java.lang.String name, java.security.PublicKey key)
Identity i = new KeyManagerIdentity(name);
i.setPublicKey(key);
addIdentity(i);
|
public synchronized void | addIdentity(java.security.Identity identity)
if (mIdentities.contains(identity))
throw new KeyManagementException("This KeyManager already contains "
+ identity.getName() + ".");
if (mIdentities.containsKey(identity.getPublicKey()))
throw new KeyManagementException("This KeyManager already contains "
+ identity.getName() + "'s key.");
mIdentities.put(identity.getPublicKey(), identity);
|
public static oreilly.jonathan.security.KeyManager | create(java.lang.String file, java.lang.String name, java.security.KeyPair pair)
KeyManager km = new KeyManager(name, pair);
km.mKeyFile = file;
return km;
|
public synchronized java.security.Identity | getIdentity(java.lang.String name)
Enumeration e = mIdentities.elements();
while (e.hasMoreElements()) {
Identity i = (Identity)e.nextElement();
if (i.getName().equals(name))
return i;
}
return null;
|
public java.security.Identity | getIdentity(java.security.PublicKey key)
return (Identity)mIdentities.get(key);
|
public static oreilly.jonathan.security.KeyManager | getInstance(java.lang.String file)
ObjectInputStream in = new ObjectInputStream(
new FileInputStream(file));
KeyManager km = (KeyManager)in.readObject();
in.close();
km.mKeyFile = file;
return km;
|
public java.security.PrivateKey | getPrivateKey() return mPrivateKey;
|
public synchronized java.security.PublicKey | getPublicKey(java.lang.String name)
if (name.equals(getName()))
return getPublicKey();
return getIdentity(name).getPublicKey();
|
public java.util.Enumeration | identities() return mIdentities.elements();
|
public static void | main(java.lang.String[] args)
if (args.length < 2) {
usage();
return;
}
String option = args[0];
String keyfile = args[1];
if (option.indexOf("c") != -1) {
if (args.length < 5) { usage(); return; }
String signer = args[2];
String algorithm = args[3];
int strength = NumberFormat.getInstance().parse(args[4]).intValue();
System.out.println("Initializing the KeyPairGenerator...");
KeyPairGenerator kpg = KeyPairGenerator.getInstance(algorithm);
kpg.initialize(strength);
System.out.println("Generating the key pair...");
KeyPair pair = kpg.genKeyPair();
KeyManager km = create(keyfile, signer, pair);
km.save();
System.out.println("Done.");
}
else if (option.indexOf("e") != -1) {
if (args.length < 4) { usage(); return; }
String idname = args[2];
String outfile = args[3];
KeyManager km = getInstance(keyfile);
ObjectOutputStream out = new ObjectOutputStream(
new FileOutputStream(outfile));
PublicKey key = km.getPublicKey(idname);
out.writeObject(idname);
out.writeObject(key);
out.close();
System.out.println("Done.");
}
else if (option.indexOf("i") != -1) {
if (args.length < 3) { usage(); return; }
String infile = args[2];
KeyManager km = getInstance(keyfile);
ObjectInputStream in = new ObjectInputStream(
new FileInputStream(infile));
String idname = (String)in.readObject();
PublicKey key = (PublicKey)in.readObject();
in.close();
km.addIdentity(idname, key);
km.save();
System.out.println("Done.");
}
else if (option.indexOf("r") != -1) {
if (args.length < 3) { usage(); return; }
String idname = args[2];
KeyManager km = getInstance(keyfile);
Identity i = km.getIdentity(idname);
km.removeIdentity(i);
km.save();
System.out.println("Done.");
}
else if (option.indexOf("l") != -1) {
if (args.length < 2) { usage(); return; }
KeyManager km = getInstance(keyfile);
System.out.println("KeyManager contents of " + keyfile + ":");
System.out.println(" public and private key for " + km.getName());
Enumeration e = km.identities();
while (e.hasMoreElements()) {
Identity i = (Identity)e.nextElement();
System.out.println(" public key for " + i.getName());
}
}
|
public synchronized void | removeIdentity(java.security.Identity identity)
PublicKey key = identity.getPublicKey();
if (mIdentities.containsKey(key))
mIdentities.remove(key);
else
throw new KeyManagementException("This KeyManager does not contain "
+ identity.getName() + ".");
|
public synchronized void | save()
try {
ObjectOutputStream out = new ObjectOutputStream(
new FileOutputStream(mKeyFile));
out.writeObject(this);
out.close();
}
catch (Exception e) {
System.out.println("KeyManager.save: " + e.toString());
}
|
public int | size() return mIdentities.size();
|
protected static void | usage()
System.out.println("Options:");
System.out.println(" create: -c keyfile signer algorithm strength");
System.out.println(" export: -e keyfile idname outfile");
System.out.println(" import: -i keyfile infile");
System.out.println(" remove: -r keyfile idname");
System.out.println(" list : -l keyfile");
|