public class VerifyX509 { private static Certificate getCACert; private static Certificate[] getCert; public static void main(String[] args) throws CertificateEncodingException { setURLConnection("https://www.google.com"); X509Certificate x509cert= (X509Certificate) getCert[0]; byte[] b= x509cert.getTBSCertificate(); b[0] = (byte) ~b[0]; // HOW TO UPDATE getTBSCertificate() after flipping the b[0] to make Verify() in my method verifySign() return false! verifySign(); } public static void setURLConnection(String link){ try{ int i=1; URL destinationURL = new URL(link); HttpsURLConnection con = (HttpsURLConnection) destinationURL.openConnection(); con.connect(); getCert = con.getServerCertificates(); for (Certificate c : getCert) { if (i==2) { getCACert= c; return; } i+=1; } }catch (Exception e1) { JOptionPane.showMessageDialog(null, "Error while connection! Check your Internet Connection."); e1.printStackTrace(); } } public static boolean verifySign() { try { getCert[0].verify(getCACert.getPublicKey()); return true; } catch (GeneralSecurityException e2) { return false; } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)