3

当我在 Mozilla 中添加/删除任何证书时,Mozilla 的密钥库在手动重新启动之前无法刷新。我创建了一个新的密钥库,用于从 Mozilla 获取私钥,但它不起作用。它使用了较旧的密钥库,所以即使证书已从 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;
}
4

1 回答 1

0
  1. 您可以暂时关闭安全系统并做您想做的事情,然后再次打开它。
  2. 询问用户:如果您想继续 - 请重新启动浏览器(Microsoft 风格:D)。
于 2012-11-30T14:49:53.350 回答