public byte[] signDataWithPrivateKey(byte[] data) throws UnrecoverableKeyException,
                                                     KeyStoreException,
                                                     NoSuchAlgorithmException,
                                                     InvalidKeyException,
                                                     SignatureException {
        if( pvtKeyStore == null ) {
            throw new RuntimeException( "Key store with private key not configured. Please configure it properly before using signed serialization." );
        }
        PrivateKey pvtkey = (PrivateKey) pvtKeyStore.getKey( pvtKeyAlias,
                                                             pvtKeyPassword );
        Signature sig = Signature.getInstance( SHA512WITH_RSA );
        sig.initSign( pvtkey );
        sig.update( data );
        return sig.sign();
    }
@Test
    public void testSignDataWithPrivateKey() throws UnsupportedEncodingException,
                                            UnrecoverableKeyException,
                                            InvalidKeyException,
                                            KeyStoreException,
                                            NoSuchAlgorithmException,
                                            SignatureException {
        // The server signs the data with the private key
        
        // Set properties to simulate the server
        final URL serverKeyStoreURL = getClass().getResource(KEYSTORE_SERVER_RESOURCE_NAME);
        System.setProperty( KeyStoreConstants.PROP_SIGN, Boolean.TRUE.toString() );
        System.setProperty( KeyStoreConstants.PROP_PVT_KS_URL, serverKeyStoreURL.toExternalForm() );
        System.setProperty(KeyStoreConstants.PROP_PVT_KS_PWD, KEYSTORE_SERVER_PASSWORD);
        System.setProperty( KeyStoreConstants.PROP_PVT_ALIAS, KEY_ALIAS );
        System.setProperty( KeyStoreConstants.PROP_PVT_PWD, KEY_PASSWORD );
        final KeyStoreHelper serverHelper = new KeyStoreHelper();

        // get some data to sign
        final byte[] data = "Hello World".getBytes("UTF8" );

        // sign the data
        final byte[] signature = serverHelper.signDataWithPrivateKey(data );

        // now, initialise the client helper
        
        // Set properties to simulate the client
        final URL clientKeyStoreURL = getClass().getResource(KEYSTORE_CLIENT_RESOURCE_NAME );
        System.setProperty( KeyStoreConstants.PROP_SIGN, Boolean.TRUE.toString() );
        System.setProperty( KeyStoreConstants.PROP_PUB_KS_URL, clientKeyStoreURL.toExternalForm() );
        System.setProperty( KeyStoreConstants.PROP_PUB_KS_PWD, KEYSTORE_CLIENT_PASSWORD );
        // client needs no password to access the certificate and public key
        final KeyStoreHelper clientHelper = new KeyStoreHelper( );

        // check the signature against the data
        assertThat(clientHelper.checkDataWithPublicKey(KEY_ALIAS,
                data,
                signature)).isTrue();

        // check some fake data
        assertThat(clientHelper.checkDataWithPublicKey(KEY_ALIAS,
                "fake".getBytes("UTF8"),
                signature)).isFalse();
    }