diff --git a/apps/files_encryption/lib/keymanager.php b/apps/files_encryption/lib/keymanager.php
index 8d3e72b422b537d3fa58df10c84c36b8465cd5f1..b207b1437ba1c96f834226ffb45ab80916dae238 100755
--- a/apps/files_encryption/lib/keymanager.php
+++ b/apps/files_encryption/lib/keymanager.php
@@ -125,8 +125,8 @@ class Keymanager {
 		$proxyStatus = \OC_FileProxy::$enabled;
 		\OC_FileProxy::$enabled = false;
 
-		//here we need the currently logged in user, while userId can be a different user
-		$util = new Util($view, \OCP\User::getUser());
+		$userId = Helper::getUser($path);
+		$util = new Util($view, $userId);
 		list($owner, $filename) = $util->getUidAndFilename($path);
 
 		// in case of system wide mount points the keys are stored directly in the data directory
@@ -225,7 +225,8 @@ class Keymanager {
 
 		$trimmed = ltrim($path, '/');
 
-		$util = new Util($view, \OCP\User::getUser());
+		$userId = Helper::getUser($path);
+		$util = new Util($view, $userId);
 
 		if($util->isSystemWideMountPoint($path)) {
 			$keyPath = '/files_encryption/keyfiles/' . $trimmed;
@@ -322,8 +323,10 @@ class Keymanager {
 
 		// $shareKeys must be  an array with the following format:
 		// [userId] => [encrypted key]
-		// Here we need the currently logged in user, while userId can be a different user
-		$util = new Util($view, \OCP\User::getUser());
+
+		$userId = Helper::getUser($path);
+
+		$util = new Util($view, $userId);
 
 		list($owner, $filename) = $util->getUidAndFilename($path);
 
@@ -441,8 +444,9 @@ class Keymanager {
 		$proxyStatus = \OC_FileProxy::$enabled;
 		\OC_FileProxy::$enabled = false;
 
-		//here we need the currently logged in user, while userId can be a different user
-		$util = new Util($view, \OCP\User::getUser());
+		$userId = Helper::getUser($filePath);
+
+		$util = new Util($view, $userId);
 
 		list($owner, $filename) = $util->getUidAndFilename($filePath);
 
diff --git a/apps/files_encryption/lib/stream.php b/apps/files_encryption/lib/stream.php
index 393c133d765c9b9a61fe6ca02ac0edc5ce91136e..2497e56e89811da95d72e2fb73571214ee5a8c68 100644
--- a/apps/files_encryption/lib/stream.php
+++ b/apps/files_encryption/lib/stream.php
@@ -92,10 +92,14 @@ class Stream {
 
 		$this->session = new \OCA\Encryption\Session($this->rootView);
 
-		$this->privateKey = $this->session->getPrivateKey($this->userId);
+		$this->privateKey = $this->session->getPrivateKey();
 
-		$util = new Util($this->rootView, \OCP\USER::getUser());
+		$userId = Helper::getUser($path);
 
+		$util = new Util($this->rootView, $userId);
+
+		// need to get the userId once more from util, because now this can be the
+		// public share key ID
 		$this->userId = $util->getUserId();
 
 		// rawPath is relative to the data directory
@@ -509,7 +513,9 @@ class Stream {
 				// Check if OC sharing api is enabled
 				$sharingEnabled = \OCP\Share::isEnabled();
 
-				$util = new Util($this->rootView, $this->userId);
+				$userId = Helper::getUser($this->rawPath);
+
+				$util = new Util($this->rootView, $userId);
 
 				// Get all users sharing the file includes current user
 				$uniqueUserIds = $util->getSharingUsersArray($sharingEnabled, $this->relPath, $this->userId);
diff --git a/apps/files_encryption/lib/util.php b/apps/files_encryption/lib/util.php
index ce3d253cc93f38f4393d9c9123894ee09ae3a56f..1e8b852fb319d0a6d386aa2be3afba6f959004fb 100644
--- a/apps/files_encryption/lib/util.php
+++ b/apps/files_encryption/lib/util.php
@@ -69,7 +69,7 @@ class Util {
 		$this->userFilesDir =
 				'/' . $userId . '/' . $this->fileFolderName; // TODO: Does this need to be user configurable?
 		$this->publicKeyDir = '/' . 'public-keys';
-		$this->encryptionDir = '/' . $this->userId . '/' . 'files_encryption';
+		$this->encryptionDir = '/' . $userId . '/' . 'files_encryption';
 		$this->keyfilesPath = $this->encryptionDir . '/' . 'keyfiles';
 		$this->shareKeysPath = $this->encryptionDir . '/' . 'share-keys';
 		$this->publicKeyPath =