edu.vt.middleware.crypt.symmetric
Class SymmetricCli

java.lang.Object
  extended by edu.vt.middleware.crypt.AbstractCli
      extended by edu.vt.middleware.crypt.AbstractEncryptionCli
          extended by edu.vt.middleware.crypt.symmetric.SymmetricCli

public class SymmetricCli
extends AbstractEncryptionCli

Command line interface for symmetric encryption operations.

Version:
$Revision: 12 $
Author:
Middleware Services

Field Summary
protected static String OPT_DIGEST
          Digest algorithm used with PBE modes that allow it.
protected static String OPT_GENKEY
          Generate key option.
protected static String OPT_ITERATIONS
          Iteration count for PBE key generation.
protected static String OPT_IV
          Cipher initialization vector option.
protected static String OPT_KEY
          Cipher key option.
protected static String OPT_KEYSIZE
          Cipher key size.
protected static String OPT_MODE
          Cipher mode option.
protected static String OPT_PADDING
          Cipher padding option.
protected static String OPT_PBE
          Trigger password-based encryption key generation.
protected static String OPT_SALT
          Salt for PBE key generation.
protected static String OPT_SCHEME
          PBE key generation strategy, e.g.
 
Fields inherited from class edu.vt.middleware.crypt.AbstractEncryptionCli
OPT_CIPHER, OPT_DECRYPT, OPT_ENCODING, OPT_ENCRYPT, OPT_OUTFILE, OPT_TAIL
 
Fields inherited from class edu.vt.middleware.crypt.AbstractCli
BASE_64_ENCODING, HEX_ENCODING, OPT_EXAMPLE, OPT_INFILE, options, PEM_SUFFIX
 
Constructor Summary
SymmetricCli()
           
 
Method Summary
protected  void decrypt(org.apache.commons.cli.CommandLine line)
          Perform a decryption operation using data specified on the command line.
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  void encrypt(org.apache.commons.cli.CommandLine line)
          Perform an encryption operation using data specified on the command line.
protected  SecretKey generatePBEKey(SymmetricAlgorithm alg, org.apache.commons.cli.CommandLine line)
          Generates a PBE key from command line options including a password.
protected  void genKey(org.apache.commons.cli.CommandLine line)
          Generate a new encryption key to using command line arguments.
protected  String getCommandName()
          Gets the name of the command for which this class provides a CLI interface.
protected  EncryptionScheme getPBEScheme(SymmetricAlgorithm alg, org.apache.commons.cli.CommandLine line)
          Gets a password-based encryption scheme based on command line arguments.
protected  void initOptions()
          Initialize CLI options.
static void main(String[] args)
          CLI entry point method.
protected  SymmetricAlgorithm newAlgorithm(org.apache.commons.cli.CommandLine line)
          Creates a new symmetric encryption algorithm instance based on CLI options.
protected  SecretKey readKey(org.apache.commons.cli.CommandLine line)
          Creates a symmetric key from a file defined by CLI arguments.
protected  void validateOptions(org.apache.commons.cli.CommandLine line)
          Validates the existence of required options for an operation.
 
Methods inherited from class edu.vt.middleware.crypt.AbstractEncryptionCli
decrypt, encrypt, getInputStream, getOutputStream
 
Methods inherited from class edu.vt.middleware.crypt.AbstractCli
closeStream, closeStream, 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_MODE

protected static final String OPT_MODE
Cipher mode option.

See Also:
Constant Field Values

OPT_PADDING

protected static final String OPT_PADDING
Cipher padding option.

See Also:
Constant Field Values

OPT_IV

protected static final String OPT_IV
Cipher initialization vector option.

See Also:
Constant Field Values

OPT_KEY

protected static final String OPT_KEY
Cipher key option.

See Also:
Constant Field Values

OPT_KEYSIZE

protected static final String OPT_KEYSIZE
Cipher key size.

See Also:
Constant Field Values

OPT_PBE

protected static final String OPT_PBE
Trigger password-based encryption key generation.

See Also:
Constant Field Values

OPT_SCHEME

protected static final String OPT_SCHEME
PBE key generation strategy, e.g. PKCS5S1

See Also:
Constant Field Values

OPT_DIGEST

protected static final String OPT_DIGEST
Digest algorithm used with PBE modes that allow it.

See Also:
Constant Field Values

OPT_SALT

protected static final String OPT_SALT
Salt for PBE key generation.

See Also:
Constant Field Values

OPT_ITERATIONS

protected static final String OPT_ITERATIONS
Iteration count for PBE key generation.

See Also:
Constant Field Values

OPT_GENKEY

protected static final String OPT_GENKEY
Generate key option.

See Also:
Constant Field Values
Constructor Detail

SymmetricCli

public SymmetricCli()
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 AbstractEncryptionCli

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.

newAlgorithm

protected SymmetricAlgorithm newAlgorithm(org.apache.commons.cli.CommandLine line)
Creates a new symmetric encryption algorithm instance based on CLI options.

Parameters:
line - Parsed command line arguments container.
Returns:
New instance of an initialized symmetric algorithm.

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.

encrypt

protected void encrypt(org.apache.commons.cli.CommandLine line)
                throws Exception
Perform an encryption operation using data specified on the command line.

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

decrypt

protected void decrypt(org.apache.commons.cli.CommandLine line)
                throws Exception
Perform a decryption operation using data specified on the command line.

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

genKey

protected void genKey(org.apache.commons.cli.CommandLine line)
               throws Exception
Generate a new encryption key to using command line arguments.

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

generatePBEKey

protected SecretKey generatePBEKey(SymmetricAlgorithm alg,
                                   org.apache.commons.cli.CommandLine line)
                            throws Exception
Generates a PBE key from command line options including a password.

Parameters:
alg - Symmetric algorithm for which a compatible key should be generated.
line - Parsed command line arguments container.
Returns:
Secret key from password.
Throws:
Exception - On key generation errors.

readKey

protected SecretKey readKey(org.apache.commons.cli.CommandLine line)
                     throws CryptException,
                            IOException
Creates a symmetric key from a file defined by CLI arguments.

Parameters:
line - Parsed command line arguments container.
Returns:
Symmetric encryption/decryption key.
Throws:
CryptException - On cryptographic errors.
IOException - On IO 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.

getPBEScheme

protected EncryptionScheme getPBEScheme(SymmetricAlgorithm alg,
                                        org.apache.commons.cli.CommandLine line)
Gets a password-based encryption scheme based on command line arguments.

Parameters:
alg - Symmetric cipher algorithm.
line - parsed command line arguments container.
Returns:
Initialized encryption scheme.


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