gpt4 book ai didi

java - 如果不重新启动 Firefox, keystore 不会刷新

转载 作者:行者123 更新时间:2023-12-02 08:26:47 24 4
gpt4 key购买 nike

当我在 Mozilla 中添加/删除任何证书时,Mozilla 的 keystore 无法刷新,直到手动重新启动。我创建了一个新的 keystore 来从 Mozilla 获取私钥,但它不起作用。它使用了较旧的 keystore ,因此即使证书已从 Mozilla 中删除,我也可以获得私钥。我该如何解决?代码如下:

public String Decrypt(String text, String pubkey) throws Exception
{
System.out.println("------INSIDE IEPublicDecrypt METHOD------ ");
X509Certificate cerificate = null;
PrivateKey privatekey = null;
KeyStore keyStorenew = null;
String aliasnew = null;
//new code for security

if (browserName.equalsIgnoreCase("Netscape")) {
System.out.println("Initializing Firefox");
createPolicyFile();
makeCfgFile();
String strCfg = System.getProperty("user.home") + File.separator
+ "jdk6-nss-mozilla.cfg";
System.out.println("String Configuration File " + strCfg);

try {
Provider p1 = new sun.security.pkcs11.SunPKCS11(strCfg);
Security.addProvider(p1);
System.out.println("Provider Added");
keyStorenew = KeyStore.getInstance("PKCS11");
System.out.println("Key Store instance created");
keyStorenew.load(null, "password".toCharArray());
System.out.println("Key Store loaded");
} catch (Exception e) {
System.out.println("Certificate Not found in browser");
}
}
if (keyStorenew != null) {
//initBrowserCertifcates();
Enumeration<String> enumeration = keyStorenew.aliases();
while (enumeration.hasMoreElements()) {
aliasnew = enumeration.nextElement();


try {
cerificate = (X509Certificate) keyStorenew.getCertificate(aliasnew);
System.out.println("Certificate found in browser========"+cerificate);
}
catch (Exception e) {
// TODO: handle exception
}
}
System.out.println("Browser Certificate Initialized.");
} else {
System.out.println("========= Keystore is NULL ==========");

}

if(keyPairMap != null)
{
System.out.println("keyPairMap is not NuLL.");
privatekey=keyPairMap.get(pubkey.toString());
}
else
{
System.out.println("keyPairMap is NuLL.");
}
System.out.println("------GOT PRIVATEKEY------ " + privatekey);
BASE64Decoder base64Decoder = new BASE64Decoder();
byte[] encryptText = base64Decoder.decodeBuffer(text);
System.out.println("------GOT ENCRYTEDTEXT------ "
+ encryptText.toString());
Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
System.out.println("------GOT CIPHER------ " + cipher);
cipher.init(Cipher.DECRYPT_MODE, privatekey);
System.out.println("------CIPHET INITIALISED------ ");
String decryptedString = new String(cipher.doFinal(encryptText));
System.out.println("------GOT DECRYPTEDTEXT------ " + decryptedString);
return decryptedString;
}

最佳答案

  1. 您可以暂时关闭安全系统并执行您想要的操作,然后再次将其打开。
  2. 询问用户:如果您想继续 - 请重新启动浏览器(Microsoft 风格:D)。

关于java - 如果不重新启动 Firefox, keystore 不会刷新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11644133/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com