tribble.security
Class KeyReader

java.lang.Object
  extended bytribble.security.KeyReader

public class KeyReader
extends java.lang.Object

Public/private encryption key reader. Provides the capability of reading public or private encryption keys contained in XML text files that were generated by class GenKeyPair.

Note that this is not a full-fledged XML parser, but rather an extemely simplified scanner that assumes that the XML input text is in a particular format. Input XML text that deviates too far from the assumed format will not be parsed correctly.

Since:
2003-03-14
Version:
$Revision: 1.3 $ $Date: 2003/03/18 03:28:09 $
Author:
David R. Tribble, david@tribble.com.
Copyright 2003 by David R. Tribble, all rights reserved.
Permission is granted to freely use and distribute this source code provided that the original copyright and authorship notices remain intact.
See Also:
main(java.lang.String[]), GenKeyPair

Constructor Summary
KeyReader(java.io.Reader in)
          Constructor.
 
Method Summary
 void close()
          Close the input stream.
static void main(java.lang.String[] args)
          Read one or more XML keyfiles and display information about the public or private encryption keys.
 java.security.Key readKey()
          Read a public or private encryption key from the XML input stream of this key reader.
 java.security.Key readKey(java.lang.String passphrase)
          Read a public or private encryption key from the XML input stream of this key reader.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

KeyReader

public KeyReader(java.io.Reader in)
Constructor.

Parameters:
in - Input stream, from which XML encryption keys are to be read.
Since:
1.1, 2003-03-14
Method Detail

main

public static void main(java.lang.String[] args)
                 throws java.io.IOException,
                        java.security.GeneralSecurityException
Read one or more XML keyfiles and display information about the public or private encryption keys.

Usage

    java tribble.security.KeyReader [option...] keyfile.xml ...
 

Options:

-p phrase
Unprotect private keys by decrypting them with a passphrase. By default, private keys are not decrypted.

Throws:
java.io.IOException
java.security.GeneralSecurityException
Since:
1.1, 2003-03-14

close

public void close()
           throws java.io.IOException
Close the input stream. Closes the underlying XML input stream for this encryption key reader.

Throws:
java.io.IOException - Thrown if an I/O (read) error occurs.
Since:
1.1, 2003-03-14

readKey

public java.security.Key readKey()
                          throws java.io.IOException,
                                 java.security.GeneralSecurityException
Read a public or private encryption key from the XML input stream of this key reader.

Note that this is not a full-fledged XML parser, but rather an extemely simplified scanner that assumes that the XML input text is in a particular format. Input XML text that deviates too far from the assumed format will not be parsed correctly.

Returns:
A public or private encryption key, or null if the end of the input stream was reached before finding a key.
Throws:
java.io.IOException - Thrown if an I/O (read) error occurs.
java.security.GeneralSecurityException
Since:
1.1, 2003-03-14

readKey

public java.security.Key readKey(java.lang.String passphrase)
                          throws java.io.IOException,
                                 java.security.GeneralSecurityException
Read a public or private encryption key from the XML input stream of this key reader.

Note that this is not a full-fledged XML parser, but rather an extemely simplified scanner that assumes that the XML input text is in a particular format. Input XML text that deviates too far from the assumed format will not be parsed correctly.

Parameters:
passphrase - Passphrase to use to decrypt private keys.
Returns:
A public or private encryption key, or null if the end of the input stream was reached before finding a key.
Throws:
java.io.IOException - Thrown if an I/O (read) error occurs.
java.security.GeneralSecurityException
Since:
1.4, 2003-03-27