Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Encrypter->decrypt issue? #2970

Closed
Valkhan opened this issue May 11, 2020 · 1 comment
Closed

Bug: Encrypter->decrypt issue? #2970

Valkhan opened this issue May 11, 2020 · 1 comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them

Comments

@Valkhan
Copy link

Valkhan commented May 11, 2020

Describe the bug
I've set an Encryption key, and i'm testing the decryption process, when not passing the 2nd argument everything looks fine, but when I encrypt with a different key as follow i've came across what could be a critical problem:

CodeIgniter 4 version
4.0.3

Affected module(s)
\Config\Services::encrypter()

Expected behavior, and steps to reproduce if appropriate

$crypt = \Config\Services::encrypter();

$userKey = base64_encode($crypt->key . 'usermail@gmail.com');  //creating unique key for user

$userData = $crypt->encrypt('user sensitive data', $userKey); 

// Allright here, passed user key and it passes and decrypts as intended
echo "<h3>Decrypted + correct userkey: ", $crypt->decrypt($userData,$userKey), "</h3>";

// here passing a wrong key it throws an error as intended
echo "<h3>Decrypted + wrong userkey: ", $crypt->decrypt($userData, 'wrongkey'), "</h3>";

// !!! BUG HERE!!!
//  I believe that when i'm not passing 2nd arg, it is using the default key ($crypt->key), it SHOULD throw an error, but instead it decrypts correctly
echo "<h3>Decrypted - without userkey: ", $crypt->decrypt($userData), "</h3>";

Context

  • OS: debian
  • Web server Apache 2.4
  • PHP version 7.4
@Valkhan Valkhan added the bug Verified issues on the current code behavior or pull requests that will fix them label May 11, 2020
@lonnieezell
Copy link
Member

Reading through the docs that Jim wrote, it looks to me that is not a bug - but the intended way it should work. It is designed so that you shouldn't have to pass a key at all, which would mean that it would use the key set in the config file by default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
Development

No branches or pull requests

2 participants