/** * Get the key as a packed binary string * * @return string */ protected function getKey() { // first create a sha256 hash of the key $hash = hash('sha256', $this->key); // create a binary string from the hash $binary = hex2bin($hash); // limit the key size based on our encryption method $keySize = AesEnum::getKeySize($this->method); $key = substr($binary, 0, $keySize); return $key; }
/** * Get the openssl formatted encryption method * * @return string */ private function getEncryptionMethod() { $keySize = AesEnum::getKeySize($this->getMethod()) * 8; return 'aes-' . $keySize . '-' . self::ENCRYPTION_MODE; }