edu.vt.middleware.crypt.signature
Class SignatureCli

java.lang.Object
  extended by edu.vt.middleware.crypt.AbstractCli
      extended by edu.vt.middleware.crypt.signature.SignatureCli

public class SignatureCli
extends AbstractCli

Command line interface for cryptographic signature operations.

Version:
$Revision: 2745 $
Author:
Middleware Services

Field Summary
protected static String OPT_ALG
          Signature algorithm option.
protected static String OPT_DIGEST
          Message digest used to produce encoded message to sign.
protected static String OPT_ENCODING
          Output encoding format.
protected static String OPT_KEY
          Path to key used for signing or verification.
protected static String OPT_SIGN
          Sign operation option.
protected static String OPT_VERIFY
          Verify operation option.
 
Fields inherited from class edu.vt.middleware.crypt.AbstractCli
BASE_64_ENCODING, HEX_ENCODING, OPT_EXAMPLE, OPT_INFILE, options, PEM_SUFFIX
 
Constructor Summary
SignatureCli()
           
 
Method Summary
protected  void dispatch(org.apache.commons.cli.CommandLine line)
          Dispatch command line data to the handler that can perform the operation requested on the command line.
protected  String getCommandName()
          Gets the name of the command for which this class provides a CLI interface.
protected  void initOptions()
          Initialize CLI options.
static void main(String[] args)
          CLI entry point method.
protected  SignatureAlgorithm newInstance(org.apache.commons.cli.CommandLine line)
          Creates a new signature algorithm instance based on command line args.
protected  PrivateKey readPrivateKey(org.apache.commons.cli.CommandLine line)
          Creates a private key from a file defined by CLI arguments.
protected  PublicKey readPublicKey(org.apache.commons.cli.CommandLine line)
          Creates a public key from a file defined by CLI arguments.
protected  byte[] readSignature(org.apache.commons.cli.CommandLine line)
          Reads a cryptographic signature from a file, possibly in encoded format, and returns the result as the raw signature bytes.
protected  void sign(org.apache.commons.cli.CommandLine line)
          Perform a signature operation on input data.
protected  void validateOptions(org.apache.commons.cli.CommandLine line)
          Validates the existence of required options for an operation.
protected  void verify(org.apache.commons.cli.CommandLine line)
          Perform a verification operation on input data.
 
Methods inherited from class edu.vt.middleware.crypt.AbstractCli
closeStream, closeStream, getInputStream, getInputStream, performAction, printExamples, printHelp
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OPT_ALG

protected static final String OPT_ALG
Signature algorithm option.

See Also:
Constant Field Values

OPT_ENCODING

protected static final String OPT_ENCODING
Output encoding format.

See Also:
Constant Field Values

OPT_DIGEST

protected static final String OPT_DIGEST
Message digest used to produce encoded message to sign.

See Also:
Constant Field Values

OPT_KEY

protected static final String OPT_KEY
Path to key used for signing or verification.

See Also:
Constant Field Values

OPT_SIGN

protected static final String OPT_SIGN
Sign operation option.

See Also:
Constant Field Values

OPT_VERIFY

protected static final String OPT_VERIFY
Verify operation option.

See Also:
Constant Field Values
Constructor Detail

SignatureCli

public SignatureCli()
Method Detail

main

public static void main(String[] args)
CLI entry point method.

Parameters:
args - Command line arguments.

initOptions

protected void initOptions()
Initialize CLI options.

Overrides:
initOptions in class AbstractCli

dispatch

protected void dispatch(org.apache.commons.cli.CommandLine line)
                 throws Exception
Dispatch command line data to the handler that can perform the operation requested on the command line.

Specified by:
dispatch in class AbstractCli
Parameters:
line - Parsed command line arguments container.
Throws:
Exception - On errors thrown by handler.

getCommandName

protected String getCommandName()
Gets the name of the command for which this class provides a CLI interface.

Specified by:
getCommandName in class AbstractCli
Returns:
Name of CLI command.

newInstance

protected SignatureAlgorithm newInstance(org.apache.commons.cli.CommandLine line)
Creates a new signature algorithm instance based on command line args.

Parameters:
line - Parsed command line arguments container.
Returns:
New instance from CLI args.

sign

protected void sign(org.apache.commons.cli.CommandLine line)
             throws Exception
Perform a signature operation on input data.

Parameters:
line - Parsed command line arguments container.
Throws:
Exception - On sign errors.

verify

protected void verify(org.apache.commons.cli.CommandLine line)
               throws Exception
Perform a verification operation on input data.

Parameters:
line - Parsed command line arguments container.
Throws:
Exception - On sign errors.

readPublicKey

protected PublicKey readPublicKey(org.apache.commons.cli.CommandLine line)
                           throws Exception
Creates a public key from a file defined by CLI arguments.

Parameters:
line - Parsed command line arguments container.
Returns:
Public key used for signature verification.
Throws:
Exception - On IO or key format errors.

readPrivateKey

protected PrivateKey readPrivateKey(org.apache.commons.cli.CommandLine line)
                             throws CryptException,
                                    IOException
Creates a private key from a file defined by CLI arguments.

Parameters:
line - Parsed command line arguments container.
Returns:
Private key.
Throws:
CryptException - On crypto errors.
IOException - On I/O errors.

readSignature

protected byte[] readSignature(org.apache.commons.cli.CommandLine line)
                        throws IOException
Reads a cryptographic signature from a file, possibly in encoded format, and returns the result as the raw signature bytes.

Parameters:
line - Parsed command line arguments container.
Returns:
Signature bytes.
Throws:
IOException - On read errors.

validateOptions

protected void validateOptions(org.apache.commons.cli.CommandLine line)
Validates the existence of required options for an operation.

Parameters:
line - Parsed command line arguments container.


Copyright © 2003-2013 Virginia Tech. All Rights Reserved.