import com.eruces.teagent.TEAgentConnection;
import com.eruces.teagent.TEAgentException;
import com.eruces.teagent.TEAgentConnectionFactory;
import com.eruces.teagent.TEAgentMatrix;
import java.util.TreeMap;
public class Sample_Java_Hash
{
public void testHash() throws TEAgentException
{
String strSingleData = "test string";
String strSalt = "test salt";
String strHashed = "";
TEAgentMatrix matrix = new TEAgentMatrix();
strHashed = TEAgentMatrix.performHash(strSingleData, strSalt);
System.out.println("Data = " + strSingleData);
System.out.println("Salt = " + strSalt);
System.out.println("Hash value = " + strHashed);
int nRows = 2;
int nCols = 3;
int i, j;
String strData [][] = new String[nRows][nCols];
String strHashVals [] = new String[nRows];
String strSalt2 = "another test salt";
for(i = 0; i < nRows; i++)
{
strHashVals[i] = "";
for(j = 0; j < nCols; j++)
strData[i][j] = "test string" + "(" + i + ", " + j + ")";
}
matrix = new TEAgentMatrix();
for(i = 0; i < strData.length; i++)
{
for(j = 0; j < strData[i].length; j++)
matrix.setRawElement(strData[i][j].getBytes(), i+1, j+1);
}
int nRow2Hash = 1;
TreeMap<Integer, byte[]> treeMap = new TreeMap<Integer, byte[]>();
treeMap.put(Integer.valueOf(nRow2Hash), strSalt2.getBytes());
matrix.setHashColumns(treeMap);
System.out.println();
System.out.println( "Hash value for column " + nRow2Hash + ":");
for(i = 1; i <= matrix.getRowCount(); i++)
{
String strTemp = new String(matrix.getRawElement(i, nRow2Hash));
strHashVals[i-1] = matrix.getHashElement(i, nRow2Hash, "" );
System.out.println( "Data: " + strTemp + " Hash value: " + strHashVals[i-1]);
}
}
public static void main()
{
try
{
Sample_Java_Hash java_hash = new Sample_Java_Hash();
java_hash.testHash();
}
catch (TEAgentException te)
{
te.printStackTrace();
System.exit(0);
}
}
}