Create Key
The Java_TEKey_CreateKey is used to create a key.
Code Samples
See the Java environment settings for details on setting the project environment.
Java_TEKey_CreateKey.java
The following example demonstrates the use of the Java_TEKey_CreateKey.
/*****************************************************************************************
*
* Java_TEKey_CreateKey.java
*
******************************************************************************************/
import com.eruces.teagent.TEAgentSSLMConnection;
import com.eruces.teagent.TEAgentException;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.FileNotFoundException;
import com.eruces.teagent.TEKey;
import com.eruces.teagent.TEAgentConnection;
import java.util.Vector;
import com.eruces.teadmin.Administration;
import com.eruces.teagent.TEAgentConnectionFactory;
import com.eruces.teagent.PAny;
import com.eruces.teconfig.AdminConfig;
import com.eruces.teconfig.REParameterInfo;
import com.eruces.teconfig.TEParameterInfo;
public class Java_TEKey_CreateKey {
private TEAgentConnection m_conn;
public void connect_native(String strServerName, int nPort, String strUsername, String strPasswd) throws TEAgentException
{
// Get a connection instance
m_conn = TEAgentConnectionFactory.getInstance(TEAgentConnectionFactory.USER_PASSWORD);
// Make connection
m_conn.open(strServerName, nPort, strUsername, strPasswd);
System.out.println("Connected to " + strServerName + " at " + nPort + " as " + strUsername);
}
public void connect_native_admin(String strServerName, int nPort, String strUsername, String strPasswd) throws TEAgentException
{
m_conn = TEAgentConnectionFactory.getInstance(TEAgentConnectionFactory.SECURE_USER_PASSWORD);
// Connect to server.
m_conn.open(strServerName, nPort, strUsername, strPasswd);
System.out.println("Connected to " + strServerName + " at " + nPort + " as " + strUsername);
}
public void connect_cert(String strServerName, int nPort, String strCertFile, String strPasswd) throws Exception
{
try {
// Get a connection for native user
TEAgentSSLMConnection sslmConn = new TEAgentSSLMConnection();
// Read pfx file
InputStream pfx = new FileInputStream(strCertFile);
// Make connection
sslmConn.open(strServerName, nPort, pfx, strPasswd);
m_conn = sslmConn;
System.out.println("Connected to " + strServerName + " at " + nPort + " as certificate user.");
}
catch(FileNotFoundException fnfex) {
throw new Exception(fnfex.getMessage());
}
}
public void disconnect() throws TEAgentException
{
// Close connection
m_conn.close();
System.out.println("Disconnected from server ");
}
public void testCreateKey() throws TEAgentException, Exception {
System.out.println();
System.out.println("Create key:");
TEKey teKey = new TEKey();
connect_native("sampleserver", 8080, "ls", "password");
//connect_cert("sampleserver", 8888, "C:\\Documents and Settings\\Administrator\\pkcs12_private_key.pfx", "password");
teKey.attachConnection(m_conn);
String strACLTemplateName = "";
String strHL = teKey.createKey(strACLTemplateName);
teKey.detachConnection();
disconnect();
System.out.println("Key was created, strHL = " + strHL);
}
public static void main(String[] args)
{
try
{
Java_TEKey_CreateKey java_test = new Java_TEKey_CreateKey();
java_test.testCreateKey();
}
catch (TEAgentException te)
{
te.printStackTrace();
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
}
/*************************************************************************************
Create key:
Connected to sampleserver at 8888 as ls
Disconnected from server
Key was created, strHL = AAAAAZ+qwyvrOEWfpn01dQs9TelNmkV8cMLeIvy3O7Lmq9COM/Suyg==
*************************************************************************************/