How to Customize Encryption chars in Yii2

I use this to encrypt my $id


$encrypted = utf8_encode(Yii::$app->security->encryptByKey($id, $key));

it displays like


þ@FN_ßcU6Y3758ce74fecf8a9c355f4ea3bd31d9a1daeda79ecd17aa85b40962a4c51675f70ïó+ýËTaJpiȹsÅå ÓZt

but i dont want this junk chars…I need a clean alphanumeric+special chars with limited chars are enough.where do i need to customize this?

You can use base64_encode() and base64_decode() to get ASCII chars.

1 Like

Hi samdark

Thanks for your reply.

I use this base64_encode($encrypted) but the chars are very lengthy any options to define this? like




base64_encode($encrypted,16) // generates 16 chars



Well, that’s correct. Encryption in Yii is quite strong so resulting string is lengthy. What do you need it for?