3
我試圖在客戶端和服務器之間進行加密通信。當服務器啓動其公共和私人RSA密鑰生成時。客戶端向服務器請求其公鑰,服務器向客戶端發送密鑰。服務器發送JSON格式公鑰:Java:使用GSON序列化RSA公鑰
Gson gson = new Gson();
String key = gson.toJson(pubKey);
而且客戶端我試圖獲得與關鍵:
Gson gson = new Gson();
PublicKey pubServerKey = gson.fromJson(responce_json, PublicKey.class);
但所描述的here
所以我我得到異常m試圖爲pubServerKey定義一個InstanceCreator,就像下面的代碼一樣
class PublicKeyInstanceCreator implements InstanceCreator<PublicKey> {
public PublicKey createInstance(Type type) {
return new PublicKey(Object.class, 0L);
}
}
但是這個我得到的語法錯誤:無法實例化類型PublicKey
你能告訴我如何解決這個問題嗎? 在這種情況下,Json是將RSA公鑰從服務器傳遞給客戶端的好方法嗎?
可以感謝一些幫助,謝謝。