Crypto

class OC\Security\Crypto
Class Crypto provides a high-level encryption layer using AES-CBC. If no key has been provided
it will use the secret defined in config.php as key. Additionally the message will be HMAC’d.
Usage:
$encryptWithDefaultPassword = \OC::$server->getCrypto()->encrypt(‘EncryptedText’);
$encryptWithCustompassword = \OC::$server->getCrypto()->encrypt(‘EncryptedText’, ‘password’);
Source:lib/private/Security/Crypto.php#49
Implements:OCP\Security\ICrypto

Properties

Methods

public OC\Security\Crypto::__construct($config)
Source:

lib/private/Security/Crypto.php#61

Parameters:
public OC\Security\Crypto::calculateHMAC($message, $password="")
Source:

lib/private/Security/Crypto.php#71

Parameters:
  • $message (string) The message to authenticate
  • $password (string) Password to use (defaults to secret in config.php)
Returns:

string Calculated HMAC

public OC\Security\Crypto::encrypt($plaintext, $password="")
Encrypts a value and adds an HMAC (Encrypt-Then-MAC)
Source:

lib/private/Security/Crypto.php#90

Parameters:
  • $plaintext (string)
  • $password (string) Password to encrypt, if not specified the secret from config.php will be taken
Returns:

string Authenticated ciphertext

public OC\Security\Crypto::decrypt($authenticatedCiphertext, $password="")
Decrypts a value and verifies the HMAC (Encrypt-Then-Mac)
Source:

lib/private/Security/Crypto.php#115

Parameters:
  • $authenticatedCiphertext (string)
  • $password (string) Password to encrypt, if not specified the secret from config.php will be taken
Returns:

string plaintext

Throws:

\Exception If the HMAC does not match

Throws:

\Exception If the decryption failed

Throws:

\Exception If the HMAC does not match

Throws:

\Exception If the decryption failed