You are here

public function OpenSSLEncryption::encrypt in Ubercart 8.4

Encrypts plaintext.

Parameters

string $key: Key used for encryption.

string $plaintext: Text string to be encrypted.

int $sourcelen: Minimum $plaintext length. Plaintext which is shorter than $sourcelen will be padded by appending spaces.

Return value

string Cyphertext. String containing encrypted text.

Overrides EncryptionInterface::encrypt

File

uc_store/src/OpenSSLEncryption.php, line 73

Class

OpenSSLEncryption
Provides encryption and decryption using OpenSSL.

Namespace

Drupal\uc_store

Code

public function encrypt($key, $plaintext, $sourcelen = 0) {
  $iv = Crypt::randomBytes(16);
  $encrypted = openssl_encrypt($plaintext, $this->cypher, $key, OPENSSL_RAW_DATA, $iv);
  if (FALSE === $encrypted) {
    $this->errors[] = t('Unknown error encrypting plaintext.');
  }
  return bin2hex($iv) . base64_encode($encrypted);
}