diff --git a/apps/encryption/appinfo/encryption.php b/apps/encryption/appinfo/encryption.php
index 8be3cae5ad5aa8f5b619f7e195fa90ef5ab85f59..d57f1b0b7bf554ce0aa7ca8fdff76e551931f604 100644
--- a/apps/encryption/appinfo/encryption.php
+++ b/apps/encryption/appinfo/encryption.php
@@ -125,6 +125,7 @@ class Encryption extends \OCP\AppFramework\App {
 					$c->query('Crypt'),
 					$server->getConfig(),
 					$server->getUserSession(),
+					$server->getSession(),
 					$server->getMemCacheFactory(),
 					$server->getLogger()
 				);
diff --git a/apps/encryption/lib/crypto/encryption.php b/apps/encryption/lib/crypto/encryption.php
index 516d7b1304a41ee9a63c27ec3d22783b714c7df5..43d3b842688de9a83afc1606293ddd87a41aeca3 100644
--- a/apps/encryption/lib/crypto/encryption.php
+++ b/apps/encryption/lib/crypto/encryption.php
@@ -95,7 +95,7 @@ class Encryption implements IEncryptionModule {
 		$this->writeCache = '';
 		$this->isWriteOperation = false;
 
-		$this->fileKey = $this->keymanager->getFileKey($path);
+		$this->fileKey = $this->keymanager->getFileKey($path, $this->user);
 
 		return array('cipher' => $this->cipher);
 	}
diff --git a/apps/encryption/lib/keymanager.php b/apps/encryption/lib/keymanager.php
index 59f904ecf17f5af198ed177c8f3e95811a4f3706..4b898217d6a8c6881f633f24dff51d9cc3ab5de4 100644
--- a/apps/encryption/lib/keymanager.php
+++ b/apps/encryption/lib/keymanager.php
@@ -32,6 +32,7 @@ use OCP\ICacheFactory;
 use OCP\IConfig;
 use OCP\ILogger;
 use OCP\IUserSession;
+use \OCP\ISession;
 
 class KeyManager {
 
@@ -86,16 +87,24 @@ class KeyManager {
 	 */
 	private $log;
 
+	/**
+	 * @var \OCP\ISession
+	 */
+	private $session;
+
 	/**
 	 * @param IStorage $keyStorage
 	 * @param Crypt $crypt
 	 * @param IConfig $config
-	 * @param IUserSession $userSession
+	 * @param Session $userSession
+	 * @param \OCP\ISession $session
 	 * @param ICacheFactory $cacheFactory
 	 * @param ILogger $log
 	 */
-	public function __construct(IStorage $keyStorage, Crypt $crypt, IConfig $config, IUserSession $userSession, ICacheFactory $cacheFactory, ILogger $log) {
+	public function __construct(IStorage $keyStorage, Crypt $crypt, IConfig $config,
+		IUserSession $userSession, ISession $session ,ICacheFactory $cacheFactory, ILogger $log) {
 
+		$this->session = $session;
 		$this->keyStorage = $keyStorage;
 		$this->crypt = $crypt;
 		$this->config = $config;
@@ -215,6 +224,9 @@ class KeyManager {
 			return false;
 		}
 
+
+		$this->session->set('privateKey', $privateKey);
+		$this->session->set('initStatus', true);
 		self::$cacheFactory->set('privateKey', $privateKey);
 		self::$cacheFactory->set('initStatus', true);
 
@@ -239,18 +251,30 @@ class KeyManager {
 
 	/**
 	 * @param $path
-	 * @return mixed
+	 * @param $uid
+	 * @return string
 	 */
-	public function getFileKey($path) {
-		return $this->keyStorage->getFileKey($path, $this->fileKeyId);
+	public function getFileKey($path, $uid) {
+		$key = '';
+		$encryptedFileKey = $this->keyStorage->getFileKey($path, $this->fileKeyId);
+		$shareKey = $this->getShareKey($path, $uid);
+		$privateKey = $this->session->get('privateKey');
+
+		if ($encryptedFileKey && $shareKey && $privateKey) {
+			$key = $this->crypt->multiKeyDecrypt($encryptedFileKey, $shareKey, $privateKey);
+		}
+
+		return $key;
 	}
 
 	/**
 	 * @param $path
+	 * @param $uid
 	 * @return mixed
 	 */
-	public function getShareKey($path) {
-		return $this->keyStorage->getFileKey($path, $this->keyId . $this->shareKeyId);
+	public function getShareKey($path, $uid) {
+		$keyId = $uid . '.' . $this->shareKeyId;
+		return $this->keyStorage->getFileKey($path, $keyId);
 	}
 
 	/**