make methods private which are not used from outside
This commit is contained in:
parent
930f0e4c18
commit
97e910e087
|
@ -23,6 +23,10 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* TODO: Check if methods really need to be public
|
||||||
|
*/
|
||||||
|
|
||||||
namespace OCA\Encryption;
|
namespace OCA\Encryption;
|
||||||
|
|
||||||
//require_once '../3rdparty/Crypt_Blowfish/Blowfish.php';
|
//require_once '../3rdparty/Crypt_Blowfish/Blowfish.php';
|
||||||
|
@ -84,7 +88,7 @@ class Crypt {
|
||||||
* blocks with encryption alone, hence padding is added to achieve the
|
* blocks with encryption alone, hence padding is added to achieve the
|
||||||
* required length.
|
* required length.
|
||||||
*/
|
*/
|
||||||
public static function addPadding($data) {
|
private static function addPadding($data) {
|
||||||
|
|
||||||
$padded = $data . 'xx';
|
$padded = $data . 'xx';
|
||||||
|
|
||||||
|
@ -97,7 +101,7 @@ class Crypt {
|
||||||
* @param string $padded padded data to remove padding from
|
* @param string $padded padded data to remove padding from
|
||||||
* @return string unpadded data on success, false on error
|
* @return string unpadded data on success, false on error
|
||||||
*/
|
*/
|
||||||
public static function removePadding($padded) {
|
private static function removePadding($padded) {
|
||||||
|
|
||||||
if (substr($padded, -2) === 'xx') {
|
if (substr($padded, -2) === 'xx') {
|
||||||
|
|
||||||
|
@ -205,7 +209,7 @@ class Crypt {
|
||||||
* @param string $passphrase
|
* @param string $passphrase
|
||||||
* @return string encrypted file content
|
* @return string encrypted file content
|
||||||
*/
|
*/
|
||||||
public static function encrypt($plainContent, $iv, $passphrase = '') {
|
private static function encrypt($plainContent, $iv, $passphrase = '') {
|
||||||
|
|
||||||
if ($encryptedContent = openssl_encrypt($plainContent, 'AES-128-CFB', $passphrase, false, $iv)) {
|
if ($encryptedContent = openssl_encrypt($plainContent, 'AES-128-CFB', $passphrase, false, $iv)) {
|
||||||
return $encryptedContent;
|
return $encryptedContent;
|
||||||
|
@ -226,7 +230,7 @@ class Crypt {
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
* @return string decrypted file content
|
* @return string decrypted file content
|
||||||
*/
|
*/
|
||||||
public static function decrypt($encryptedContent, $iv, $passphrase) {
|
private static function decrypt($encryptedContent, $iv, $passphrase) {
|
||||||
|
|
||||||
if ($plainContent = openssl_decrypt($encryptedContent, 'AES-128-CFB', $passphrase, false, $iv)) {
|
if ($plainContent = openssl_decrypt($encryptedContent, 'AES-128-CFB', $passphrase, false, $iv)) {
|
||||||
|
|
||||||
|
@ -246,7 +250,7 @@ class Crypt {
|
||||||
* @param string $iv IV to be concatenated
|
* @param string $iv IV to be concatenated
|
||||||
* @returns string concatenated content
|
* @returns string concatenated content
|
||||||
*/
|
*/
|
||||||
public static function concatIv($content, $iv) {
|
private static function concatIv($content, $iv) {
|
||||||
|
|
||||||
$combined = $content . '00iv00' . $iv;
|
$combined = $content . '00iv00' . $iv;
|
||||||
|
|
||||||
|
@ -259,7 +263,7 @@ class Crypt {
|
||||||
* @param string $catFile concatenated data to be split
|
* @param string $catFile concatenated data to be split
|
||||||
* @returns array keys: encrypted, iv
|
* @returns array keys: encrypted, iv
|
||||||
*/
|
*/
|
||||||
public static function splitIv($catFile) {
|
private static function splitIv($catFile) {
|
||||||
|
|
||||||
// Fetch encryption metadata from end of file
|
// Fetch encryption metadata from end of file
|
||||||
$meta = substr($catFile, -22);
|
$meta = substr($catFile, -22);
|
||||||
|
@ -376,34 +380,6 @@ class Crypt {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Creates symmetric keyfile content using a generated key
|
|
||||||
* @param string $plainContent content to be encrypted
|
|
||||||
* @returns array keys: key, encrypted
|
|
||||||
* @note symmetricDecryptFileContent() can be used to decrypt files created using this method
|
|
||||||
*
|
|
||||||
* This function decrypts a file
|
|
||||||
*/
|
|
||||||
public static function symmetricEncryptFileContentKeyfile($plainContent) {
|
|
||||||
|
|
||||||
$key = self::generateKey();
|
|
||||||
|
|
||||||
if ($encryptedContent = self::symmetricEncryptFileContent($plainContent, $key)) {
|
|
||||||
|
|
||||||
return array(
|
|
||||||
'key' => $key,
|
|
||||||
'encrypted' => $encryptedContent
|
|
||||||
);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
return false;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Create asymmetrically encrypted keyfile content using a generated key
|
* @brief Create asymmetrically encrypted keyfile content using a generated key
|
||||||
* @param string $plainContent content to be encrypted
|
* @param string $plainContent content to be encrypted
|
||||||
|
@ -486,43 +462,11 @@ class Crypt {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Asymetrically encrypt a string using a public key
|
|
||||||
* @param $plainContent
|
|
||||||
* @param $publicKey
|
|
||||||
* @return string encrypted file
|
|
||||||
*/
|
|
||||||
public static function keyEncrypt($plainContent, $publicKey) {
|
|
||||||
|
|
||||||
openssl_public_encrypt($plainContent, $encryptedContent, $publicKey);
|
|
||||||
|
|
||||||
return $encryptedContent;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Asymetrically decrypt a file using a private key
|
|
||||||
* @param $encryptedContent
|
|
||||||
* @param $privatekey
|
|
||||||
* @return string decrypted file
|
|
||||||
*/
|
|
||||||
public static function keyDecrypt($encryptedContent, $privatekey) {
|
|
||||||
|
|
||||||
$result = @openssl_private_decrypt($encryptedContent, $plainContent, $privatekey);
|
|
||||||
|
|
||||||
if ($result) {
|
|
||||||
return $plainContent;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Generates a pseudo random initialisation vector
|
* @brief Generates a pseudo random initialisation vector
|
||||||
* @return String $iv generated IV
|
* @return String $iv generated IV
|
||||||
*/
|
*/
|
||||||
public static function generateIv() {
|
private static function generateIv() {
|
||||||
|
|
||||||
if ($random = openssl_random_pseudo_bytes(12, $strong)) {
|
if ($random = openssl_random_pseudo_bytes(12, $strong)) {
|
||||||
|
|
||||||
|
@ -548,7 +492,7 @@ class Crypt {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Generate a pseudo random 1024kb ASCII key
|
* @brief Generate a pseudo random 1024kb ASCII key, used as file key
|
||||||
* @returns $key Generated key
|
* @returns $key Generated key
|
||||||
*/
|
*/
|
||||||
public static function generateKey() {
|
public static function generateKey() {
|
||||||
|
@ -580,7 +524,7 @@ class Crypt {
|
||||||
*
|
*
|
||||||
* if the key is left out, the default handeler will be used
|
* if the key is left out, the default handeler will be used
|
||||||
*/
|
*/
|
||||||
public static function getBlowfish($key = '') {
|
private static function getBlowfish($key = '') {
|
||||||
|
|
||||||
if ($key) {
|
if ($key) {
|
||||||
|
|
||||||
|
@ -594,38 +538,6 @@ class Crypt {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $passphrase
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public static function legacyCreateKey($passphrase) {
|
|
||||||
|
|
||||||
// Generate a random integer
|
|
||||||
$key = mt_rand(10000, 99999) . mt_rand(10000, 99999) . mt_rand(10000, 99999) . mt_rand(10000, 99999);
|
|
||||||
|
|
||||||
// Encrypt the key with the passphrase
|
|
||||||
$legacyEncKey = self::legacyEncrypt($key, $passphrase);
|
|
||||||
|
|
||||||
return $legacyEncKey;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief encrypts content using legacy blowfish system
|
|
||||||
* @param string $content the cleartext message you want to encrypt
|
|
||||||
* @param string $passphrase
|
|
||||||
* @returns string encrypted content
|
|
||||||
*
|
|
||||||
* This function encrypts an content
|
|
||||||
*/
|
|
||||||
public static function legacyEncrypt($content, $passphrase = '') {
|
|
||||||
|
|
||||||
$bf = self::getBlowfish($passphrase);
|
|
||||||
|
|
||||||
return $bf->encrypt($content);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief decrypts content using legacy blowfish system
|
* @brief decrypts content using legacy blowfish system
|
||||||
* @param string $content the cleartext message you want to decrypt
|
* @param string $content the cleartext message you want to decrypt
|
||||||
|
|
Loading…
Reference in New Issue