summaryrefslogtreecommitdiffstats
path: root/apps/encryption/lib/crypto/crypt.php
diff options
context:
space:
mode:
authorBjoern Schiessle <schiessle@owncloud.com>2015-03-26 12:23:36 +0100
committerThomas Müller <thomas.mueller@tmit.eu>2015-04-07 13:30:27 +0200
commit198b73fe322281a297fd8fcc5e7a10762996ce86 (patch)
tree63511d685368b5569e5eb2906fc9e38f3045b043 /apps/encryption/lib/crypto/crypt.php
parent7ffd77fac9f0baadbbaac6e0dd7e62de78197b52 (diff)
downloadnextcloud-server-198b73fe322281a297fd8fcc5e7a10762996ce86.tar.gz
nextcloud-server-198b73fe322281a297fd8fcc5e7a10762996ce86.zip
write encrypted file to disc
Diffstat (limited to 'apps/encryption/lib/crypto/crypt.php')
-rw-r--r--apps/encryption/lib/crypto/crypt.php16
1 files changed, 16 insertions, 0 deletions
diff --git a/apps/encryption/lib/crypto/crypt.php b/apps/encryption/lib/crypto/crypt.php
index 9fb93485ef7..c9f02bfa1cc 100644
--- a/apps/encryption/lib/crypto/crypt.php
+++ b/apps/encryption/lib/crypto/crypt.php
@@ -25,6 +25,7 @@ namespace OCA\Encryption\Crypto;
use OC\Encryption\Exceptions\DecryptionFailedException;
use OC\Encryption\Exceptions\EncryptionFailedException;
use OC\Encryption\Exceptions\GenericEncryptionException;
+use OCA\Encryption\KeyManager;
use OCA\Files_Encryption\Exception\MultiKeyDecryptException;
use OCA\Files_Encryption\Exception\MultiKeyEncryptException;
use OCP\IConfig;
@@ -380,6 +381,21 @@ class Crypt {
}
/**
+ * Generate a pseudo random 256-bit ASCII key, used as file key
+ * @return string
+ */
+ public static function generateFileKey() {
+ // Generate key
+ $key = base64_encode(openssl_random_pseudo_bytes(32, $strong));
+ if (!$key || !$strong) {
+ // If OpenSSL indicates randomness is insecure, log error
+ throw new \Exception('Encryption library, Insecure symmetric key was generated using openssl_random_pseudo_bytes()');
+ }
+
+ return $key;
+ }
+
+ /**
* Check if a file's contents contains an IV and is symmetrically encrypted
*
* @param $content