*\r
*/\r
\r
+/*\r
+ * TODO: Check if methods really need to be public\r
+ */\r
+\r
namespace OCA\Encryption;\r
\r
//require_once '../3rdparty/Crypt_Blowfish/Blowfish.php';\r
* blocks with encryption alone, hence padding is added to achieve the\r
* required length.\r
*/\r
- public static function addPadding($data) {\r
+ private static function addPadding($data) {\r
\r
$padded = $data . 'xx';\r
\r
* @param string $padded padded data to remove padding from\r
* @return string unpadded data on success, false on error\r
*/\r
- public static function removePadding($padded) {\r
+ private static function removePadding($padded) {\r
\r
if (substr($padded, -2) === 'xx') {\r
\r
* @param string $passphrase\r
* @return string encrypted file content\r
*/\r
- public static function encrypt($plainContent, $iv, $passphrase = '') {\r
+ private static function encrypt($plainContent, $iv, $passphrase = '') {\r
\r
if ($encryptedContent = openssl_encrypt($plainContent, 'AES-128-CFB', $passphrase, false, $iv)) {\r
return $encryptedContent;\r
* @throws \Exception\r
* @return string decrypted file content\r
*/\r
- public static function decrypt($encryptedContent, $iv, $passphrase) {\r
+ private static function decrypt($encryptedContent, $iv, $passphrase) {\r
\r
if ($plainContent = openssl_decrypt($encryptedContent, 'AES-128-CFB', $passphrase, false, $iv)) {\r
\r
* @param string $iv IV to be concatenated\r
* @returns string concatenated content\r
*/\r
- public static function concatIv($content, $iv) {\r
+ private static function concatIv($content, $iv) {\r
\r
$combined = $content . '00iv00' . $iv;\r
\r
* @param string $catFile concatenated data to be split\r
* @returns array keys: encrypted, iv\r
*/\r
- public static function splitIv($catFile) {\r
+ private static function splitIv($catFile) {\r
\r
// Fetch encryption metadata from end of file\r
$meta = substr($catFile, -22);\r
\r
}\r
\r
-\r
- /**\r
- * @brief Creates symmetric keyfile content using a generated key\r
- * @param string $plainContent content to be encrypted\r
- * @returns array keys: key, encrypted\r
- * @note symmetricDecryptFileContent() can be used to decrypt files created using this method\r
- *\r
- * This function decrypts a file\r
- */\r
- public static function symmetricEncryptFileContentKeyfile($plainContent) {\r
-\r
- $key = self::generateKey();\r
-\r
- if ($encryptedContent = self::symmetricEncryptFileContent($plainContent, $key)) {\r
-\r
- return array(\r
- 'key' => $key,\r
- 'encrypted' => $encryptedContent\r
- );\r
-\r
- } else {\r
-\r
- return false;\r
-\r
- }\r
-\r
- }\r
-\r
/**\r
* @brief Create asymmetrically encrypted keyfile content using a generated key\r
* @param string $plainContent content to be encrypted\r
\r
}\r
\r
- /**\r
- * @brief Asymetrically encrypt a string using a public key\r
- * @param $plainContent\r
- * @param $publicKey\r
- * @return string encrypted file\r
- */\r
- public static function keyEncrypt($plainContent, $publicKey) {\r
-\r
- openssl_public_encrypt($plainContent, $encryptedContent, $publicKey);\r
-\r
- return $encryptedContent;\r
-\r
- }\r
-\r
- /**\r
- * @brief Asymetrically decrypt a file using a private key\r
- * @param $encryptedContent\r
- * @param $privatekey\r
- * @return string decrypted file\r
- */\r
- public static function keyDecrypt($encryptedContent, $privatekey) {\r
-\r
- $result = @openssl_private_decrypt($encryptedContent, $plainContent, $privatekey);\r
-\r
- if ($result) {\r
- return $plainContent;\r
- }\r
-\r
- return $result;\r
-\r
- }\r
-\r
/**\r
* @brief Generates a pseudo random initialisation vector\r
* @return String $iv generated IV\r
*/\r
- public static function generateIv() {\r
+ private static function generateIv() {\r
\r
if ($random = openssl_random_pseudo_bytes(12, $strong)) {\r
\r
}\r
\r
/**\r
- * @brief Generate a pseudo random 1024kb ASCII key\r
+ * @brief Generate a pseudo random 1024kb ASCII key, used as file key\r
* @returns $key Generated key\r
*/\r
public static function generateKey() {\r
*\r
* if the key is left out, the default handeler will be used\r
*/\r
- public static function getBlowfish($key = '') {\r
+ private static function getBlowfish($key = '') {\r
\r
if ($key) {\r
\r
\r
}\r
\r
- /**\r
- * @param $passphrase\r
- * @return mixed\r
- */\r
- public static function legacyCreateKey($passphrase) {\r
-\r
- // Generate a random integer\r
- $key = mt_rand(10000, 99999) . mt_rand(10000, 99999) . mt_rand(10000, 99999) . mt_rand(10000, 99999);\r
-\r
- // Encrypt the key with the passphrase\r
- $legacyEncKey = self::legacyEncrypt($key, $passphrase);\r
-\r
- return $legacyEncKey;\r
-\r
- }\r
-\r
- /**\r
- * @brief encrypts content using legacy blowfish system\r
- * @param string $content the cleartext message you want to encrypt\r
- * @param string $passphrase\r
- * @returns string encrypted content\r
- *\r
- * This function encrypts an content\r
- */\r
- public static function legacyEncrypt($content, $passphrase = '') {\r
-\r
- $bf = self::getBlowfish($passphrase);\r
-\r
- return $bf->encrypt($content);\r
-\r
- }\r
-\r
/**\r
* @brief decrypts content using legacy blowfish system\r
* @param string $content the cleartext message you want to decrypt\r