public static boolean matchingKeys(final PrivateKey privateKey,
                                final PublicKey publicKey) throws GeneralSecurityException {
        Signature sign = Signature.getInstance(SIGNING_ALGORITHM);

        byte[] bytes = SAMPLE_CHALLANGE.getBytes(StandardCharsets.UTF_8);

        sign.initSign(privateKey);
        sign.update(bytes);
        byte[] signature = sign.sign();

        sign.initVerify(publicKey);
        sign.update(bytes);
        return sign.verify(signature);
    }
@Test
    void testMatchingPrivatePublicKeysInvalid() throws Exception {
        KeyPairGenerator keyGen1 = KeyPairGenerator.getInstance(KEY_GENERATION_ALGORITHM);
        keyGen1.initialize(2048);
        final java.security.KeyPair keyPair1 = keyGen1.genKeyPair();
        KeyPairGenerator keyGen2 = KeyPairGenerator.getInstance(KEY_GENERATION_ALGORITHM);
        keyGen2.initialize(2048);
        final java.security.KeyPair keyPair2 = keyGen2.genKeyPair();
        //mixing keys from different pairs
        Assertions.assertThat(KeystoreUtils.matchingKeys(keyPair1.getPrivate(), keyPair2.getPublic())).isFalse();
    }