Quantcast
Channel: Thales Simulator Library
Viewing all articles
Browse latest Browse all 332

New Post: How to interact with HSM using JAVA

$
0
0
Hi Juris,

I appreciate your effort for the help.
Sadly I am still unable to proceed :(. The thing is, I am unable to run any command on HSM client.
Let's say a command event A2 - this is described to generate a random component and print it.

From java, if I want to run this command, I do not know in which format to send the command.

If write A2 as byte stream after opeing a TCP/IP port to HSM, my control never returns back. I have even tried converting the command to hexadecimal and writing it
to the output stream but no luck. If there is any online material I can refer to, please share it.

Below is the code

package thales;

import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.net.Socket;
public class ThalesSimulatorClient {
public static void main(String [] args){
    try{
        ThalesSimulatorClient simulatorclient = new ThalesSimulatorClient();

        Socket socket = new Socket("localhost",9998);
        System.out.println("Socket is connected : "+socket.isConnected());
        String command = simulatorclient.toHex("A2");
        byte[] bytes = command.getBytes();
        OutputStream outputStream = socket.getOutputStream();
        BufferedOutputStream bufferedOut = new BufferedOutputStream(outputStream, 1024);
        bufferedOut.write(bytes);
        bufferedOut.flush();
        InputStream in = socket.getInputStream();
        int result;
        while((result = in.read()) != -1){
                System.out.println((char)result);
        }
        socket.close();
    }
    catch(IOException ioException){
        System.err.println("unable to connect to socket 9997");
    }
}
public String toHex(String arg) {
        String hexString =  String.format("%016x", new BigInteger(1, arg.getBytes()));
    return hexString;
}
}

Thanks,
Amrutansu

Viewing all articles
Browse latest Browse all 332

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>