2

我想用以下功能检查文件的签名

public boolean checkSignature(X509Certificate certificate, String filePath,
        byte[] bytearray) throws IOException, NoSuchAlgorithmException,
        NoSuchProviderException, InvalidKeyException, SignatureException {

    File file = new File(filePath);
    byte[] message = new byte[(int) file.length()];
    FileInputStream fis = new FileInputStream(file);
    fis.read(message);
    fis.close();

    PublicKey pubKeyRSA = certificate.getPublicKey();

    Signature sig = Signature.getInstance("SHA1withRSA");

    sig.initVerify(pubKeyRSA);
    sig.update(message);
    boolean isValid = sig.verify(bytearray);
    System.out.println("The signature verifies: " + isValid);

    return isValid;
}

但是为了线PublicKey pubKeyRSA = certificate.getPublicKey();

我得到了例外:

java.lang.IllegalStateException: Public Key algorithm not supported by any installed provider!
    at codec.x509.X509Certificate.getPublicKey(X509Certificate.java:486)
    at workpackage.XMLSigner.checkSignature(XMLSigner.java:67)
    at workpackage.WorkProgram.VerifyXmlSignature(WorkProgram.java:117)
    at workpackage.WorkProgram.main(WorkProgram.java:64)

谁能帮我解决这个问题?

4

0 回答 0