Yii2 encrypting: how to specify IV?


I have to encrypt a string in order to save it in db. However i can encrypt it using CBC mode but cant find out how to supply or get the used iv. Thanks


Sorry i forgot to say tnat i am using encryptByPassword

You can’t. It’s generated for you.


In that case is it possible to get and save the generated IV? How?

Suppose you need to encrypt in yii/php POST rest method and to be decrypted later by javascript (after REST GET method invocationHow to use the same IV in order to be able to decrypt information?


No, it is not possible currently. See the implementation of Security::encrypt().

I have seen it and no method to get iv nor to set… :frowning:

Is there any alternative solution?

$iv is not required for decryption (it’s in the data) so I’m not sure why you need it.

The output from encryptByPassword() consists of:

See Security::decrypt().