public function testBase64Encode() { $string = '!!?*!~Za_-c@#$2üäas!'; self::assertSame('ISE/KiF+WmFfLWNAIyQyw7zDpGFzIQ==', base64_encode($string)); self::assertSame('ISE_KiF-WmFfLWNAIyQyw7zDpGFzIQ', Encryption::base64Encode($string)); }
/** * Returns a base64 encoded, openssl encrypted string with the encryption * password and * a salt. * * Do not rely on the way this is encrypted, just use it in conjunction with * decrypt. * * BEWARE of any changes in different release versions because you'll might be * unable to decrypt after a change. * * If the data is not a string, it gets serialized. * * @param mixed $data */ public function encrypt($data) { if (is_string($data)) { $data = self::SERIALIZE_NONE . '-' . $data; } elseif ($this->serializationFormat === self::SERIALIZE_JSON) { $data = self::SERIALIZE_JSON . '-' . json_encode($data); } elseif ($this->serializationFormat === self::SERIALIZE_PHP) { $data = self::SERIALIZE_PHP . '-' . serialize($data); } // serialized $nonce = $this->generateNonce($this->nonceChars); if ($this->useMd5NotRandom) { // Using the md5 of data as IV $iv = substr(md5($data), 0, $this->ivMaxChars); } else { // Complete random IV $iv = $this->generateNonce(is_int($this->ivMaxChars) ? $this->ivMaxChars : $this->cipherIvLength, true); } return ($iv ? $iv . '.' : '') . Encryption::base64Encode(openssl_encrypt($this->salt . $data . $nonce, $this->cipher, $this->password, true, $this->padIv($iv, $this->cipherIvLength))); }