\OCP\SecurityICrypto

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');

Summary

Methods
Constants
calculateHMAC()
encrypt()
decrypt()
No constants found
No protected methods found
N/A
No private methods found
N/A

Methods

calculateHMAC()

calculateHMAC(string  $message, string  $password = '') : string

Parameters

string $message

The message to authenticate

string $password

Password to use (defaults to secret in config.php)

Returns

string —

Calculated HMAC

encrypt()

encrypt(string  $plaintext, string  $password = '') : string

Encrypts a value and adds an HMAC (Encrypt-Then-MAC)

Parameters

string $plaintext
string $password

Password to encrypt, if not specified the secret from config.php will be taken

Returns

string —

Authenticated ciphertext

decrypt()

decrypt(string  $authenticatedCiphertext, string  $password = '') : string

Decrypts a value and verifies the HMAC (Encrypt-Then-Mac)

Parameters

string $authenticatedCiphertext
string $password

Password to encrypt, if not specified the secret from config.php will be taken

Throws

\Exception

If the HMAC does not match

Returns

string —

plaintext