SignatureVerifier { static boolean verify(byte[] signature, String publicKeyPEM, String signedContent) { SubjectPublicKeyInfo publicKeyInfo = parsePublicKeyInfo(publicKeyPEM); PublicKey publicKey = convertPublicKeyInfoToPublicKey(publicKeyInfo); return verifySignature(signature, publicKey, signedContent); }    }
@Test public void verifyValidSignature() { String configJson = FileUtils.readFileContent(getClass().getClassLoader().getResourceAsStream("config.json")); byte[] configSignature = FileUtils.readFileContentBytes(getClass().getClassLoader().getResourceAsStream("config.rsa")); String configSignaturePublicKey = FileUtils.readFileContent(getClass().getClassLoader().getResourceAsStream("config.pub")); assertTrue(SignatureVerifier.verify(configSignature, configSignaturePublicKey, configJson)); }
@Test public void verifyInvalidSignature() { String configJson = FileUtils.readFileContent(getClass().getClassLoader().getResourceAsStream("config.json")); byte[] configSignature = FileUtils.readFileContentBytes(getClass().getClassLoader().getResourceAsStream("config.rsa")); String configSignaturePublicKey = FileUtils.readFileContent(getClass().getClassLoader().getResourceAsStream("config.pub")); assertFalse(SignatureVerifier.verify(configSignature, configSignaturePublicKey, configJson + "a")); }