Code example for PrivateKey

Methods: equals

0
        throws IOException 
    { 
        StringWriter sw = new StringWriter();
        PEMWriter pw = new PEMWriter(sw);
 
        pw.writeObject(akp);
        pw.close();
 
        String data = sw.toString();
 
        PEMParser pr = new PEMParser(new StringReader(data));
 
        Object o = pr.readObject();
 
        if (o == null || !(o instanceof PEMKeyPair))
        { 
            fail("Didn't find OpenSSL key"); 
        } 
 
        KeyPair kp = new JcaPEMKeyConverter().setProvider("BC").getKeyPair((PEMKeyPair)o);
        PrivateKey privKey = kp.getPrivate();
 
        if (!akp.equals(privKey))
        { 
            fail("Failed to read back test"); 
        } 
    } 
 
Experience pair programming with AI  Get Codota for Java