我真的需要专家来帮助我。谢谢!我编写了一个程序来从资产中读取证书文件并通过套接字发送它。
但是,以下行不起作用:
"X509Certificate clientcert=(X509Certificate)of.generateCertificate(in)"
我很困惑。整个计划如下:
private Socket client = null;
private Button button;
private FileInputStream fis = null;
private ObjectOutputStream out = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button) findViewById(R.id.button);
button.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
new Thread (new Runnable()
{
public void run()
{
try
{
client = new Socket("192.168.1.186", 4444);
out = new ObjectOutputStream(client.getOutputStream());
AssetManager assetManager = getAssets();
InputStream in;
in = assetManager.open("client.crt");
CertificateFactory of = CertificateFactory.getInstance("X.509");
X509Certificate clientcert = (X509Certificate) of.generateCertificate(in);
out.writeObject(clientcert);
in.close();
out.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}).start();
}
});
}
答案 0 :(得分:1)
您好请尝试以下方式阅读证书:
CertificateFactory.getInstance("X.509").generateCertificate(new FileInputStream("path")));