![]() I suspect that the "base64:X, where X=44 character string" value that you are referring to is found in some configuration file, which typically should contain readable characters only. It allows you to represent a collection of bytes by means of ASCII characters only. That is why the Base64 translation comes in. Unlike the common usage of the type string, in this case it is not a printable string but just a collection of bytes, 16 or 32 of them. What may confuse you is the usage of the term string. This makes sense, because in the end, keys for AES are nothing but a bunch of random bytes. So invoking random_bytes() (or its openssl equivalent) is all you need to do, either asking for 16 bytes (in case of AES-128-CBC) or 32 bytes (in case of AES-256-CBC). Public static function generateKey($cipher) * Create a new encryption key for the given cipher. I am not in the position to try this myself, but check out the source code here: /** So how does one generate a valid AES-256-CBC key, and how does one store it? If base64 is required, how does that work? Encoding a 64 generated hex key gives me back a 88 character string back. How does one read a key with this prefix of base64:? How to get this back to a regular string.įor now I have settled with this 16 character string, but doesn't seem right. I am not sure if this is right but I have a hard time getting this. I read somewhere that AES-256-CBC needs a key of 64 characters of which 44 characters should be base64. Laravel itself uses a key something similar like this: ![]() However, it does work with setting it to 8 bit, with a 16 character key. I also tried to set it to 16 byte, with a 32 character key. The only supported ciphers are AES-128-CBC and AES-256-CBC with the correct key lengths I get a 64 long hex string, that I would like to save on both ends, so both have access to on one side encrypt and the other side decrypt.īut somehow this key is not accepted. $key = bin2hex(openssl_random_pseudo_bytes(32, $cstrong)) So I thought, I need a 32 byte key like this: ![]() Default laravel encryption is set to AES-256-CBC. I use Laravel 5.7 and have two apps running on different servers.
0 Comments
Leave a Reply. |