protected void readSecretKeyFromKeystore() throws Exception {
        InputStream inputStream=null;
        // must not use default keystore type - as it does not support secret keys
        KeyStore store=KeyStore.getInstance("JCEKS");

        SecretKey tempKey=null;
        try {
            if(this.secret_key == null) { // in case the secret key was set before, e.g. via injection in a unit test
                // load in keystore using this thread's classloader
                inputStream=Thread.currentThread().getContextClassLoader().getResourceAsStream(keystore_name);
                if(inputStream == null)
                    inputStream=new FileInputStream(keystore_name);
                // we can't find a keystore here -
                if(inputStream == null)
                    throw new Exception("Unable to load keystore " + keystore_name + " ensure file is on classpath");
                // we have located a file lets load the keystore
                try {
                    store.load(inputStream, store_password.toCharArray());
                    // loaded keystore - get the key
                    tempKey=(SecretKey)store.getKey(alias, key_password.toCharArray());
                }
                catch(IOException e) {
                    throw new Exception("Unable to load keystore " + keystore_name + ": " + e);
                }
                catch(NoSuchAlgorithmException e) {
                    throw new Exception("No Such algorithm " + keystore_name + ": " + e);
                }
                catch(CertificateException e) {
                    throw new Exception("Certificate exception " + keystore_name + ": " + e);
                }

                if(tempKey == null)
                    throw new Exception("Unable to retrieve key '" + alias + "' from keystore " + keystore_name);
                this.secret_key=tempKey;
                if(sym_algorithm.equals(DEFAULT_SYM_ALGO))
                    sym_algorithm=tempKey.getAlgorithm();
            }
        }
        finally {
            Util.close(inputStream);
        }
    }