Package pygar.zoneable
Class FieldCrypto
java.lang.Object
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
-
Field Summary
Fields Modifier and Type Field Description 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
Constructors Constructor Description 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
Modifier and Type Method Description 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)
-
Field Details
-
cipherEncrypt
protected javax.crypto.Cipher cipherEncrypt -
cipherDecrypt
protected javax.crypto.Cipher cipherDecrypt -
crypto
-
cipherBlockSize
protected int cipherBlockSize -
cipherOutputSize
protected int cipherOutputSize -
table
-
key
protected java.security.Key key
-
-
Constructor Details
-
FieldCrypto
public FieldCrypto(CryptoEngine crypto, java.security.Key key, EncryptedFieldTable table) throws java.security.NoSuchAlgorithmException, javax.crypto.NoSuchPaddingException, java.security.InvalidKeyExceptionCreate an object initializing it for encryption using the table definitions of the fields.- Parameters:
crypto
- the CryptoEngine object for this configurationkey
- the symmetric encryption keytable
- the definitions of the fields- Throws:
java.security.NoSuchAlgorithmException
javax.crypto.NoSuchPaddingException
java.security.InvalidKeyException
-
-
Method Details
-
encode
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 CryptoExceptionDecode 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 CryptoExceptionEncode a single field represented as a string creating an encrypted byte array using the field type specified.- Parameters:
row
- - from EncryptedFieldTable that describes the fieldvalue
-- 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 CryptoExceptionDecode a single encrypted field according to its type creating a clear text string for the value.- Parameters:
ftype
- the type of the fieldname
- the name of the fieldvalue
-- Returns:
- the decoded value as a string
- Throws:
CryptoException
-
decodeField
public abstract java.lang.String decodeField(EncryptedFieldTable.Row row, java.lang.String value) throws CryptoExceptionDecode a single encrypted field according to its type creating a clear text string for the value.- Parameters:
row
- the description of the fieldvalue
-- 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, CryptoExceptionPartially 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, CryptoExceptionDecrypt 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.ExceptionCompare 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 compareinStream2
- second xml documenttolerance
- allowable difference between two real values as a fraction of valuetable
- 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
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
-