Skip to main content

Encrypting Data

Encrypting data.


Sample_Other.java

The following code sample illustrates how to encrypt data.

import java.io.File;
import java.io.FileOutputStream;

import com.eruces.teagent.TEAgentConnection;
import com.eruces.teagent.TECipher;
import com.eruces.teagent.TECipherOutputStream;
import com.eruces.teagent.TEKey;

public class Sample_Other {

private static TEAgentConnection conn;
private static byte[] ttag;

public static void writeBMP_encrypted(String strFile, byte[] header, byte[] data) {

FileOutputStream fos = null;
TECipherOutputStream cos = null;

try {
TEKey teKey = new TEKey();
teKey.attachConnection(conn);
TECipher teCipher = teKey.exportKey(new byte[0]);

ttag = teCipher.getRawHiddenLink();

fos = new FileOutputStream(new File(strFile));
cos = new TECipherOutputStream(fos, teCipher);

fos.write(header);

int place = 0;

while (place < data.length) {
if (place + 64 < data.length) {
cos.write(data, place, 64);
place += 64;
}
else {
cos.write(data, place, data.length - place);
place += data.length;
}
}

cos.close();
fos.close();
teKey.detachConnection();
} catch (Exception e) {
e.printStackTrace();
}
}
}