title: Java to HSM connection and sending "GC" / FK" commands
body: <p>Here is code to send and receive data from HSM</p>
  
  <pre><code>public class TestHSMJava {
  public static void main(String args[]) {
      System.out.println("&lt;&lt;&lt; Main Method Entry &gt;&gt;&gt;");
      String command = null;
      Socket socket = null;
      DataOutputStream out = null;
      DataInputStream in = null;
      byte[] b= new byte[100];
      try {
          socket = new Socket("10.10.10.10", 7500);
          System.out.println("&lt;&lt;&lt; Socket &gt;&gt;&gt; :" + socket);
          if (socket != null) {
              System.out.println("&lt;&lt;&lt; Connected to HSM  &gt;&gt;&gt;:"
                      + socket.isConnected());
              in = new DataInputStream (new BufferedInputStream(socket.getInputStream()));
              out = new DataOutputStream (new BufferedOutputStream(socket.getOutputStream()));
              command = "0006303030304e43";
              out.writeUTF(command);
              System.out.println("Input to HSM : " +command);
              out.flush();
              String response = in.readUTF();
              System.out.println("Output from HSM : " +response);
              System.out.println("");
          }
      }
  }
  </code></pre>
  
  <p>The questions is which command I need to send for execute "GC" command (Translate a ZPK from LMK to ZMK Encryption) I need to generate a clear components for TPK-key. Usually I do</p>
  
  <pre><code>gc
  Enter key length [1,2,3]: 2
  Enter key type: 002
  Enter key scheme: u
  </code></pre>
  
  <p>and then</p>
  
  <pre><code>fk
  Enter key length [1,2,3]: 2
  Enter key type: 002
  Enter key scheme: u
  Enter component type [X,H,T,E,S]: x
  Enter number of components [1-9]: 2
  </code></pre>
  
  <p>I need to do those actions using Java-program. </p>