Code example for CodeSigner

Methods: equalshashCode

0
        Certificate c = cf.generateCertificate(fis);
        fis.close();
        CertPath cp = cf.generateCertPath(Collections.singletonList(c));
 
        // Create a code signer 
        CodeSigner cs = new CodeSigner(cp, new Timestamp(new Date(), cp));
 
        // Serialize the code signer 
        ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
        ObjectOutputStream out = new ObjectOutputStream(byteOut);
        out.writeObject(cs);
        out.close();
 
        // Deserialize the code signer 
        byte[] data = byteOut.toByteArray();
        CodeSigner cs2 = (CodeSigner) new ObjectInputStream(
            new ByteArrayInputStream(data)).readObject();
 
        // Test for equality 
        if (!cs.equals(cs2) || cs.hashCode() != cs2.hashCode()) {
            throw new Exception("CodeSigner serialization test FAILED");
        } 
    } 
}