Nextcloud PHP API (master)

ICrypto

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

Tags
since
8.0.0

Table of Contents

Methods

calculateHMAC()  : string
decrypt()  : string
Decrypts a value and verifies the HMAC (Encrypt-Then-Mac)
encrypt()  : string
Encrypts a value and adds an HMAC (Encrypt-Then-MAC)

Methods

calculateHMAC()

public calculateHMAC(string $message[, string $password = '' ]) : string
Parameters
$message : string

The message to authenticate

$password : string = ''

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

Tags
since
8.0.0
Return values
string

Calculated HMAC

decrypt()

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

public decrypt(string $authenticatedCiphertext[, string $password = '' ]) : string
Parameters
$authenticatedCiphertext : string
$password : string = ''

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

Tags
throws
Exception

If the HMAC does not match

throws
Exception

If the decryption failed

since
8.0.0
Return values
string

plaintext

encrypt()

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

public encrypt(string $plaintext[, string $password = '' ]) : string
Parameters
$plaintext : string
$password : string = ''

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

Tags
since
8.0.0
Return values
string

Authenticated ciphertext


        
On this page

Search results