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 classFieldCryptoXmlTxt0.ConcealRealThis class contains the algorithm for concealing or revealing real numbers.classFieldCryptoXmlTxt0.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 booleancompareStreams(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.voiddecode(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.StringdecodeField(EncryptedFieldTable.EFTYPE ftype, java.lang.String name, byte[] value)Decode a field value according to the ftype specifier returning a string.java.lang.StringdecodeField(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.StringdecodeString(java.lang.String value)voiddecryptPartiallyEncryptedStream(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.voidencode(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.StringencodeField(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.StringencodeString(java.lang.String s)Encode a string with a symmetric session key and return it as a string representation in hexadecimal.voidpartiallyEncryptStream(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.booleanverifyField(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.NoSuchAlgorithmExceptionjavax.crypto.NoSuchPaddingExceptionjava.security.InvalidKeyException
-
-
Method Details
-
decode
Description copied from class:FieldCryptoDecode 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:
decodein 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:
decodeFieldin 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:FieldCryptoEncode the in stream applying the encryption algorithm to the fields as specified in the table and placing results on the out stream.- Specified by:
encodein classFieldCrypto- Throws:
DocumentError
-
encodeString
Encode a string with a symmetric session key and return it as a string representation in hexadecimal. *- Specified by:
encodeStringin 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:
verifyFieldin classFieldCrypto- Throws:
CryptoException
-
encodeField
public java.lang.String encodeField(EncryptedFieldTable.Row row, java.lang.String value) throws CryptoExceptionDescription copied from class:FieldCryptoEncode a single field represented as a string creating an encrypted byte array using the field type specified.- Specified by:
encodeFieldin 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:FieldCryptoDecode a single encrypted field according to its type creating a clear text string for the value.- Specified by:
decodeFieldin 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:
partiallyEncryptStreamin classFieldCrypto- Throws:
javax.xml.stream.XMLStreamExceptionCryptoException
-
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:
decryptPartiallyEncryptedStreamin classFieldCrypto- Parameters:
inStream-outStream-table-- Throws:
javax.xml.stream.XMLStreamExceptionCryptoException
-
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:
compareStreamsin 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.Exceptionjavax.xml.stream.XMLStreamException
-