We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

how to make phalcon 128 character encryption?

Hi, I'm still new to Phalcon and I was wondering on how to make a 128 character encryption.

Many thanks in advance.

I don't think Phalcon has any built-in encryption functionality. You might as well just use the native PHP functions.



98.9k
Accepted
answer
edited Jul '14

If you're refering to 128-bit encryption, you can use native functions:

$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);

# creates a cipher text compatible with AES (Rijndael block size = 128)
# to keep the text confidential 
# only suitable for encoded input that never ends with value 00h
# (because of default zero padding)
$ciphertext = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $plaintext, MCRYPT_MODE_CBC, $iv);

# prepend the IV for it to be available for decryption
$ciphertext = $iv . $ciphertext;

# encode the resulting cipher text so it can be represented by a string
echo base64_encode($ciphertext);

http://php.net/manual/en/function.mcrypt-encrypt.php

With Phalcon\Crypt:

<?php

//Create an instance
$crypt = new Phalcon\Crypt();

$key = 'le password';
$text = 'This is a secret text';

$crypt->setMode(MCRYPT_MODE_CBC);
$crypt->setCipher(MCRYPT_RIJNDAEL_128);
$encrypted = $crypt->encrypt($text, $key);

http://docs.phalcon.io/en/latest/reference/crypt.html#basic-usage

thanks a lot mr. @Phalcon.