Jump to content

Laravel The only supported ciphers are AES-128-CBC and AES-256-CBC with the correct key lengths.

Joveice
Go to solution Solved by Joveice,
10 minutes ago, Lumi said:

go online, generate a random 32 character long string, base64 encode it then in your env set

APP_KEY=base64:encodedrandom32characterstring

You don't NEED to use artisan for anything in laravel, it's just a convenience. 

For the sake that I was going to use this for multiple projects, I thought about creating my own key:generate32 command which was a copy but with 32 bit value

But when looking in the code I found this

Encrypter::generateKey($this->laravel['config']['app.cipher'])

Which went to this

public static function generateKey($cipher)
    {
        return random_bytes($cipher == 'AES-128-CBC' ? 16 : 32);
    }

So by setting this in .env

APP_CIPHER=AES-256-CBC

It solved the issue and created a 32 character long string.

 

Thanks for the help anyways, would not have looked here without you.

So that's my issue.

 

  • I got a env file
  • I ran php artisan key:generate
  • In app.php there is a 'chiper' => 'AES-256-CBC',
  • Ran php artisan config:cache

I tried to use encrypt and that's the error message I get.

The only supported ciphers are AES-128-CBC and AES-256-CBC with the correct key lengths.

My key

base64:wxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=

Whats wrong?

Back-end developer, electronics "hacker"

Link to comment
Share on other sites

Link to post
Share on other sites

artisan config:clear && artisan cache:clear

i want to die

Link to comment
Share on other sites

Link to post
Share on other sites

6 minutes ago, Lumi said:

artisan config:clear && artisan cache:clear

 

14 minutes ago, Joveice said:

 

  • Ran php artisan config:cache
 

I have done that.

Back-end developer, electronics "hacker"

Link to comment
Share on other sites

Link to post
Share on other sites

7 minutes ago, Joveice said:

 

I have done that.

I said config:cache != config:clear

i want to die

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, Lumi said:

I said config:cache != config:clear

Config cache runs clear before it caches if you didn't know

Back-end developer, electronics "hacker"

Link to comment
Share on other sites

Link to post
Share on other sites

2 minutes ago, Joveice said:

Config cache runs clear before it caches if you didn't know

I'm fairly certain that's incorrect. If you have documentation on that I'd like to read it.

i want to die

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, Lumi said:

I'm fairly certain that's incorrect. If you have documentation on that I'd like to read it.

E:\Projects\mykeys>php artisan config:cache
Configuration cache cleared!
Configuration cached successfully!

E:\Projects\mykeys>

I don't think there is any documentation on artisan really.

Back-end developer, electronics "hacker"

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, Joveice said:

E:\Projects\mykeys>php artisan config:cache
Configuration cache cleared!
Configuration cached successfully!

E:\Projects\mykeys>

I don't think there is any documentation on artisan really.

I stand corrected,

Laravel's site has documentation on a lot of artisan and the artisan config:cache command says nothing about clearing it previously. Just states to not utilize it during development due to the end user making changes to the environment file. Speaking of deployment, whats the web server setup you're trying to deploy your application on?

i want to die

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, Lumi said:

I stand corrected,

Laravel's site has documentation on a lot of artisan and the artisan config:cache command says nothing about clearing it previously. Just states to not utilize it during development due to the end user making changes to the environment file. Speaking of deployment, whats the web server setup you're trying to deploy your application on?

I haven't deployed anything, it's a new project still running with artisan serve

Back-end developer, electronics "hacker"

Link to comment
Share on other sites

Link to post
Share on other sites

14 minutes ago, Joveice said:

I haven't deployed anything, it's a new project still running with artisan serve

Maybe key length mismatch? What cipher is set in your configure/app.php

i want to die

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, Lumi said:

Maybe key length mismatch? What cipher is set in your configure/app.php

 

50 minutes ago, Joveice said:
  • In app.php there is a 'chiper' => 'AES-256-CBC',
 

Everything is in the first post

Back-end developer, electronics "hacker"

Link to comment
Share on other sites

Link to post
Share on other sites

20 minutes ago, Joveice said:

 

Everything is in the first post

Double check your app keys length shouldn't be more than 32 characters for 256

Also sorry about not re-referencing the original post, I'm quite busy at the moment with other things and keep forgetting.

i want to die

Link to comment
Share on other sites

Link to post
Share on other sites

2 minutes ago, Lumi said:

Double check your app keys length shouldn't be more than 32 characters for 256

Also sorry about not re-referencing the original post, I'm quite busy at the moment with other things and keep forgetting.

It's 51 characters long, but that's what key:generate creates.

No problem, thanks for taking some of the time trying to help!

Back-end developer, electronics "hacker"

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, Joveice said:

It's 51 characters long, but that's what key:generate creates.

No problem, thanks for taking some of the time trying to help!

length after base64 decoding the key?

i want to die

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, Lumi said:

length after base64 decoding the key?

16

Back-end developer, electronics "hacker"

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, Joveice said:

16

Use 128 problem solved

i want to die

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, Lumi said:

Use 128 problem solved

I'd like to use 256, so how can I set a 32 character key? I haven't seen any way to change the key the "correct" way to a 32 character long string

Back-end developer, electronics "hacker"

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, Joveice said:

I'd like to use 256, so how can I set a 32 character key? I haven't seen any way to change the key the "correct" way to a 32 character long string

go online, generate a random 32 character long string, base64 encode it then in your env set

APP_KEY=base64:encodedrandom32characterstring

You don't NEED to use artisan for anything in laravel, it's just a convenience. 

i want to die

Link to comment
Share on other sites

Link to post
Share on other sites

10 minutes ago, Lumi said:

go online, generate a random 32 character long string, base64 encode it then in your env set

APP_KEY=base64:encodedrandom32characterstring

You don't NEED to use artisan for anything in laravel, it's just a convenience. 

For the sake that I was going to use this for multiple projects, I thought about creating my own key:generate32 command which was a copy but with 32 bit value

But when looking in the code I found this

Encrypter::generateKey($this->laravel['config']['app.cipher'])

Which went to this

public static function generateKey($cipher)
    {
        return random_bytes($cipher == 'AES-128-CBC' ? 16 : 32);
    }

So by setting this in .env

APP_CIPHER=AES-256-CBC

It solved the issue and created a 32 character long string.

 

Thanks for the help anyways, would not have looked here without you.

Back-end developer, electronics "hacker"

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×