我发现了 2 个类似的问题,并尝试运行作为解决方案给出的代码,因为这些答案对我来说不起作用,所以用代码片段提出问题。
两者都说答案不起作用,所以请不要将此问题视为重复
这是我的代码。
import com.sun.org.apache.xml.internal.security.utils.Base64;
import java.io.FileInputStream;
import java.security.PublicKey;
import java.security.Signature;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import xmlread.ReadXMLFile;
public class CertificateTest {
public static void main(String[] sdd) {
try{
FileInputStream fin = new FileInputStream("pub.arm");
CertificateFactory f = CertificateFactory.getInstance("X.509");
X509Certificate certificate = (X509Certificate) f.generateCertificate(fin);
PublicKey pk = certificate.getPublicKey();
byte[] sign = "Qn/rlJRdZAdlPpu1UmmjE+rup8rv8d6XlS9MngAorzYDXefw0vWEP4eHil3YHoA1JUkoQQOgmw0w0QZFmrQbS33sa2t76iuqXI7EtnAPU798K+hEXP88tsYDWJNJFo9DdhkGltP5dQ02DN030Q1w58aTF+yZFfY1KVOPx2bIoL8=".getBytes();
Signature sig = Signature.getInstance("SHA1withRSA");
sig.initVerify(pk);
sig.update(Base64.decode(ReadXMLFile.getString().getBytes()));
boolean verifies = sig.verify(Base64.decode(ReadXMLFile.getString().getBytes()));
System.out.println("signature verifies: " + verifies);
}catch(Exception ex){}
}
}