pygar.zoneable
Class FieldCrypto

java.lang.Object
  extended by pygar.zoneable.FieldCrypto
Direct Known Subclasses:
FieldCryptoXmlTxt0

public abstract class FieldCrypto
extends java.lang.Object

Perform the innermost encryption step: the encryption of fields but not the semantic tags of the statements.

According to the original plan, this class is abstract because there may be alternative document encodings during development and perhaps even in deployment. Thus, we introduce this abstract class and work is done in a subclass: FieldCryptoXmlTxt0

See Also:

A potential alternative method would use document tree structures that are stored and transmitted in binary. In order to supply that alternative, it will be necessary write a new implementation in a subclass.


Field Summary
protected  int cipherBlockSize
           
protected  javax.crypto.Cipher cipherDecrypt
           
protected  javax.crypto.Cipher cipherEncrypt
           
protected  int cipherOutputSize
           
protected  CryptoEngine crypto
           
protected  java.security.Key key
           
protected  EncryptedFieldTable table
           
 
Constructor Summary
FieldCrypto(CryptoEngine crypto, java.security.Key key, EncryptedFieldTable table)
          Create an object initializing it for encryption using the table definitions of the fields.
 
Method Summary
abstract  boolean compareStreams(java.io.InputStream inStream1, java.io.InputStream inStream2, java.lang.Double tolerance, EncryptedFieldTable table)
          Compare two streams containing XML documents containing fields described by the field table.
abstract  void decode(java.io.InputStream in, java.io.OutputStream out)
          Decode the in stream applying the encryption algorithm to the fields as specified in the table and placing the results on the out stream.
abstract  java.lang.String decodeField(EncryptedFieldTable.EFTYPE ftype, java.lang.String name, byte[] value)
          Decode a single encrypted field according to its type creating a clear text string for the value.
abstract  java.lang.String decodeField(EncryptedFieldTable.Row row, java.lang.String value)
          Decode a single encrypted field according to its type creating a clear text string for the value.
abstract  void decryptPartiallyEncryptedStream(java.io.InputStream inStream, java.io.OutputStream outStream, EncryptedFieldTable table)
          Decrypt the document on the inStream assuming it was partially encrypted with the current session encryption key.
abstract  void encode(java.io.InputStream in, java.io.OutputStream out)
          Encode the in stream applying the encryption algorithm to the fields as specified in the table and placing results on the out stream.
abstract  java.lang.String encodeField(EncryptedFieldTable.Row row, java.lang.String value)
          Encode a single field represented as a string creating an encrypted byte array using the field type specified.
protected abstract  java.lang.String encodeString(java.lang.String s)
          Encode a string with a symmetric session key and return it as a string representation in hexadecimal.
abstract  void partiallyEncryptStream(java.io.InputStream inStream, java.io.OutputStream outStream, EncryptedFieldTable table)
          Partially encrypt the input stream according to the specifications of the EncryptedFieldTable and using the current session key.
abstract  boolean verifyField(EncryptedFieldTable.Row row, java.lang.Double tolerance, java.lang.String value1, java.lang.String value2)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cipherEncrypt

protected javax.crypto.Cipher cipherEncrypt

cipherDecrypt

protected javax.crypto.Cipher cipherDecrypt

crypto

protected CryptoEngine crypto

cipherBlockSize

protected int cipherBlockSize

cipherOutputSize

protected int cipherOutputSize

table

protected volatile EncryptedFieldTable table

key

protected java.security.Key key
Constructor Detail

FieldCrypto

public FieldCrypto(CryptoEngine crypto,
                   java.security.Key key,
                   EncryptedFieldTable table)
            throws java.security.NoSuchAlgorithmException,
                   javax.crypto.NoSuchPaddingException,
                   java.security.InvalidKeyException
Create an object initializing it for encryption using the table definitions of the fields.

Parameters:
crypto - the CryptoEngine object for this configuration
key - the symmetric encryption key
table - the definitions of the fields
Throws:
java.security.NoSuchAlgorithmException
javax.crypto.NoSuchPaddingException
java.security.InvalidKeyException
Method Detail

encode

public abstract void encode(java.io.InputStream in,
                            java.io.OutputStream out)
                     throws DocumentError
Encode the in stream applying the encryption algorithm to the fields as specified in the table and placing results on the out stream.

Parameters:
in -
out -
Throws:
DocumentError

decode

public abstract void decode(java.io.InputStream in,
                            java.io.OutputStream out)
                     throws CryptoException
Decode the in stream applying the encryption algorithm to the fields as specified in the table and placing the results on the out stream.

Parameters:
in -
out -
Throws:
CryptoException

encodeField

public abstract java.lang.String encodeField(EncryptedFieldTable.Row row,
                                             java.lang.String value)
                                      throws CryptoException
Encode a single field represented as a string creating an encrypted byte array using the field type specified.

Parameters:
row - - from EncryptedFieldTable that describes the field
value -
Returns:
encoded value as string of hexadecimal
Throws:
CryptoException

decodeField

public abstract java.lang.String decodeField(EncryptedFieldTable.EFTYPE ftype,
                                             java.lang.String name,
                                             byte[] value)
                                      throws CryptoException
Decode a single encrypted field according to its type creating a clear text string for the value.

Parameters:
ftype - the type of the field
name - the name of the field
value -
Returns:
the decoded value as a string
Throws:
CryptoException

decodeField

public abstract java.lang.String decodeField(EncryptedFieldTable.Row row,
                                             java.lang.String value)
                                      throws CryptoException
Decode a single encrypted field according to its type creating a clear text string for the value.

Parameters:
row - the description of the field
value -
Returns:
the decoded value as a string
Throws:
CryptoException

partiallyEncryptStream

public abstract void partiallyEncryptStream(java.io.InputStream inStream,
                                            java.io.OutputStream outStream,
                                            EncryptedFieldTable table)
                                     throws javax.xml.stream.XMLStreamException,
                                            CryptoException
Partially encrypt the input stream according to the specifications of the EncryptedFieldTable and using the current session key.

Throws:
javax.xml.stream.XMLStreamException
CryptoException

decryptPartiallyEncryptedStream

public abstract void decryptPartiallyEncryptedStream(java.io.InputStream inStream,
                                                     java.io.OutputStream outStream,
                                                     EncryptedFieldTable table)
                                              throws javax.xml.stream.XMLStreamException,
                                                     CryptoException
Decrypt the document on the inStream assuming it was partially encrypted with the current session encryption key.

Parameters:
inStream -
outStream -
table -
Throws:
javax.xml.stream.XMLStreamException
CryptoException

compareStreams

public abstract boolean compareStreams(java.io.InputStream inStream1,
                                       java.io.InputStream inStream2,
                                       java.lang.Double tolerance,
                                       EncryptedFieldTable table)
                                throws javax.xml.stream.XMLStreamException,
                                       java.lang.Exception
Compare two streams containing XML documents containing fields described by the field table. Check each field for equality. Allow a tolerance in the comparison of real value fields. Other fields are compared for exact identity. This test procedure is provided to check the results a round-trip encryption and decryption.

Parameters:
inStream1 - first xml document to compare
inStream2 - second xml document
tolerance - allowable difference between two real values as a fraction of value
table - description of fields
Returns:
true if the documents and equal in every field within the tolerance
Throws:
javax.xml.stream.XMLStreamException
java.lang.Exception

verifyField

public abstract boolean verifyField(EncryptedFieldTable.Row row,
                                    java.lang.Double tolerance,
                                    java.lang.String value1,
                                    java.lang.String value2)
                             throws CryptoException
Throws:
CryptoException

encodeString

protected abstract java.lang.String encodeString(java.lang.String s)
                                          throws CryptoException
Encode a string with a symmetric session key and return it as a string representation in hexadecimal.

Parameters:
s - - clear text string
Returns:
encoded string
Throws:
CryptoException