Package pygar.zoneable
Class FieldCryptoXmlTxt0
java.lang.Object
pygar.zoneable.FieldCrypto
pygar.zoneable.FieldCryptoXmlTxt0
- Direct Known Subclasses:
FieldCryptoDemo1
@ThreadSafe public class FieldCryptoXmlTxt0 extends FieldCrypto
Perform the innermost encryption step: the encryption of fields but not the
semantic tags of the statements. This specialization of class FieldCrypto
operates on XML documents in textual form. Encrypted text is represented
in hexadecimal. This is the earliest version; it was written for demo0.
Most operations on the XML fields are fairly stable and insensitive to the
application. The one source of variability is the choice of an order preserving
encryption for numerical quantities that might be searched on range and/or
order comparison. For that reason, particular
applications may supply a subclass that contains an override for particular
encryption operations.
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
FieldCryptoXmlTxt0.ConcealReal
This class contains the algorithm for concealing or revealing real numbers.class
FieldCryptoXmlTxt0.RealDetail
-
Field Summary
Fields inherited from class pygar.zoneable.FieldCrypto
cipherBlockSize, cipherDecrypt, cipherEncrypt, cipherOutputSize, crypto, key, table
-
Constructor Summary
Constructors Constructor Description FieldCryptoXmlTxt0(CryptoEngine crypto, java.security.Key key, EncryptedFieldTable table)
-
Method Summary
Modifier and Type Method Description 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.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.java.lang.String
decodeField(EncryptedFieldTable.EFTYPE ftype, java.lang.String name, byte[] value)
Decode a field value according to the ftype specifier returning a string.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.java.lang.String
decodeString(java.lang.String value)
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.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.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 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.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.boolean
verifyField(EncryptedFieldTable.Row row, java.lang.Double tolerance, java.lang.String value1, java.lang.String value2)
-
Constructor Details
-
FieldCryptoXmlTxt0
public FieldCryptoXmlTxt0(CryptoEngine crypto, java.security.Key key, EncryptedFieldTable table) throws java.security.NoSuchAlgorithmException, javax.crypto.NoSuchPaddingException, java.security.InvalidKeyException- Throws:
java.security.NoSuchAlgorithmException
javax.crypto.NoSuchPaddingException
java.security.InvalidKeyException
-
-
Method Details
-
decode
Description copied from class:FieldCrypto
Decode the in stream applying the encryption algorithm to the fields as specified in the table and placing the results on the out stream.- Specified by:
decode
in classFieldCrypto
- Throws:
CryptoException
-
decodeField
public java.lang.String decodeField(EncryptedFieldTable.EFTYPE ftype, java.lang.String name, byte[] value) throws CryptoExceptionDecode a field value according to the ftype specifier returning a string. N.b. the internal logic is written to handle the possibility of a input byte array whose length is not a multiple of the cipherBlockSize. This does not appear to happen no doubt because of padding; therefore, the logic has never been tested for the possibility that a different encryption algorithm might not perform padding.- Specified by:
decodeField
in classFieldCrypto
- Parameters:
ftype
- the type of the fieldvalue
- the encrypted value as a byte arrayname
- the name of the field- Returns:
- the unencrypted value as a string
- Throws:
CryptoException
- if any problem occurs with decryption
-
encode
Description copied from class:FieldCrypto
Encode the in stream applying the encryption algorithm to the fields as specified in the table and placing results on the out stream.- Specified by:
encode
in classFieldCrypto
- Throws:
DocumentError
-
encodeString
Encode a string with a symmetric session key and return it as a string representation in hexadecimal. *- Specified by:
encodeString
in classFieldCrypto
- Parameters:
s
- - clear text string- Returns:
- encoded string
- Throws:
CryptoException
-
verifyField
public boolean verifyField(EncryptedFieldTable.Row row, java.lang.Double tolerance, java.lang.String value1, java.lang.String value2) throws CryptoException- Specified by:
verifyField
in classFieldCrypto
- Throws:
CryptoException
-
encodeField
public java.lang.String encodeField(EncryptedFieldTable.Row row, java.lang.String value) throws CryptoExceptionDescription copied from class:FieldCrypto
Encode a single field represented as a string creating an encrypted byte array using the field type specified.- Specified by:
encodeField
in classFieldCrypto
- Parameters:
row
- - from EncryptedFieldTable that describes the field- Returns:
- encoded value as string of hexadecimal
- Throws:
CryptoException
-
decodeString
- Throws:
CryptoException
-
decodeField
public java.lang.String decodeField(EncryptedFieldTable.Row row, java.lang.String value) throws CryptoExceptionDescription copied from class:FieldCrypto
Decode a single encrypted field according to its type creating a clear text string for the value.- Specified by:
decodeField
in classFieldCrypto
- Parameters:
row
- the description of the field- Returns:
- the decoded value as a string
- Throws:
CryptoException
-
partiallyEncryptStream
public 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.- Specified by:
partiallyEncryptStream
in classFieldCrypto
- Throws:
javax.xml.stream.XMLStreamException
CryptoException
-
decryptPartiallyEncryptedStream
public 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.- Specified by:
decryptPartiallyEncryptedStream
in classFieldCrypto
- Parameters:
inStream
-outStream
-table
-- Throws:
javax.xml.stream.XMLStreamException
CryptoException
-
compareStreams
public boolean compareStreams(java.io.InputStream inStream1, java.io.InputStream inStream2, java.lang.Double tolerance, EncryptedFieldTable table) throws 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. However note the following before using the procedure.The partial encryption allows the original document to contain fields that are simply deleted in the production of the partially encrypted document. Consequently, a decrypted copy of the document will omit these fields. Therefore be sure that inStream1 contains the original document and inStream2 contains the document produced by decryption.
- Specified by:
compareStreams
in classFieldCrypto
- 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:
java.lang.Exception
javax.xml.stream.XMLStreamException
-