Thales HSM 8000 A2命令发送(生成清除组件)

时间:2014-07-30 11:39:28

标签: java command

使用Java,我在HSM端口发送A2命令,但收到错误。

Input to HSM : 0000A2002U
Output from HSM : 0000A318

在文档中我发现A3 - 这是对A2命令的响应,18是一个错误,表示:未加载文档格式定义

我需要生成一个清除组件(不是A0命令中的键)。在控制台模式下,我使用gc命令。

Java代码:

System.out.println("<<< Connected to HSM  >>>:" + socket.isConnected());
in = new DataInputStream (new BufferedInputStream(socket.getInputStream()));
out = new DataOutputStream (new BufferedOutputStream(socket.getOutputStream()));
command = "0000A2002U";
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("");

3 个答案:

答案 0 :(得分:2)

将此数据发送至HSM:

000A30303030413230303255
**** 0 0 0 0 A 2 0 0 2 U

其中****表示以十六进制发送的数据大小。

HSM返回两帧:
一个用于命令接收,另一个用于打印信息。像这样:
000000A300U9FABB20DD3BACFD81B832D918B008B4A
000000AZ00

答案 1 :(得分:0)

    package hsm;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.net.Socket;

public class TestHSMJava {
    public static void main(String args[]) {
    System.out.println("<<< Main Method Entry >>>");

    String command = null;
    Socket socket = null;
    DataOutputStream out = null;
    DataInputStream in = null;
    byte[] b= new byte[100];
    try {
        socket = new Socket("127.0.0.1", 9998);
        System.out.println("<<< Socket >>> :" + socket);
        if (socket != null) {
           /* System.out.println("<<< Connected to HSM  >>>:"
                    + 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("..");*/
            System.out.println("<<< Connected to HSM  >>>:" + socket.isConnected());
            in = new DataInputStream (new BufferedInputStream(socket.getInputStream()));
            out = new DataOutputStream (new BufferedOutputStream(socket.getOutputStream()));
            command = "000A3030303041323030325500060000A2002U";
            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("");
    }

    } catch (Exception e) {
        // TODO: handle exception
    }
    }}

答案 2 :(得分:-1)

我认为java方法writeUTF在de命令之前放置了de message length。

您的命令必须为“3030303041323030325500060000A2002U”,因为writeUTF位于000A之前。