0

我想使用我的网站的公钥解密在客户端加密的消息:

URL httpsURL = new URL("https://mediashuttle.com/");
HttpsURLConnection connection = (HttpsURLConnection) httpsURL.openConnection();
connection.connect();
Certificate cert = connection.getServerCertificates()[0];
PublicKey publicKey = cert.getPublicKey();

现在在服务器(Tomcat)端,我想解密传递给 Servlet 的消息。你能告诉我如何在 Tomcat 中检索私钥来解密消息吗?

谢谢!

4

1 回答 1

1

您需要从存储服务器密钥的密钥库中获取密钥。像这样:

File keyStoreFile = new File("path/to/keystore/file.jks");
InputStream inputStream = new FileInputStream(keyStoreFile);

KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
keyStore.load(inputStream, "password".toCharArray());
Key key = keyStore.getKey("yourKeyAlias", "changeit".toCharArray());
Cipher cipher = Cipher.getInstance("RSA");
cipher.init(Cipher.DECRYPT_MODE, key);
byte[] encrypted = getEncripted();
byte[] decrypted = cipher.doFinal(encrypted);
于 2013-04-18T01:16:49.420 回答