0
下面是代碼從HSM發送和接收數據Java來HSM連接,併發送「GC」/FK」命令
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("10.10.10.10", 7500);
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("");
}
}
}
的問題是命令我需要發送的執行命令‘GC’(翻譯從LMK一個ZPK到ZMK加密),我需要生成TPK鍵清晰的組件。通常我做
gc
Enter key length [1,2,3]: 2
Enter key type: 002
Enter key scheme: u
然後
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
我需要使用Java程序執行這些操作。
我嘗試發送相同的命令,我的HSM,但我得到的答覆是000b3030303041303030303135,當其轉換爲ASCII是0000A000015。這裏可能是什麼問題? –