v5 crypt #16010
Replies: 5 comments 2 replies
-
I don't experience what you do with the same code. I wrote a test as follows: $key = substr(md5(uniqid()), 0, 16); // 16 characters long
$source = 'BvQrk+D^b&saR/L#mQig+8V9v^W&S/&moY7';
$crypt = new Crypt();
$crypt->setKey($key);
$encrypted = $crypt->encryptBase64($source);
// This one I got it by echoing the `$encrypted` above using php 7.4
$expected = 'wwj9F2tFQPF81WXtEEZxymsv+QxnqCJc7yc1nUz8YB+vpj/b5BoTWQmazy2FxWAroiJJfA==';
$actual = $encrypted;
$I->assertSame($expected, $actual);
$expected = $source;
$actual = $crypt->decryptBase64($encrypted);
$I->assertSame($expected, $actual); This test passes on all versions. If there was a discrepancy in the PHP versions, the latter part of the test would fail. I am not sure why you get a much smaller encrypted string according to your code |
Beta Was this translation helpful? Give feedback.
-
what if the key is not 16 chars? the sample was with '123456' and the original has 128 chars. can it be the reason? EDIT: only when using the encrypt values stored in the bd from php7.3 & phalcon4 |
Beta Was this translation helpful? Give feedback.
-
Actually, that did not work. I got a different encryption value every time I run the tests. It should be like that really. Encrypting a value should not return the same encrypted string to avoid exploits. The example I gave above was wrong (I corrected the code - wrong variable assignment). Still, old hashes should work, so long as you kept the algorithm the same. Honestly I do not know why your encrypted value is so short. |
Beta Was this translation helpful? Give feedback.
-
I think you need to rehash all the stored values (if possible). If those are passwords or something like that you can reset all of them. I am not sure what else to suggest. The changes to |
Beta Was this translation helpful? Give feedback.
-
i think i will go with the rehash. thank you for the fastest reply ever! Phalcon style :) |
Beta Was this translation helpful? Give feedback.
-
Migrating from php7.3 with phalcon4 to phalcon5 with php8.1
got some problems with the crypt
from php7.3 with phalcon 4
app/services.php
`
from php8.1 with phalcon5
origins
\Exception: Hash does not match. from: phalcon/Encryption/Crypt.zep at line: 224
also encryptBase64('test') in php8.1 phalcon5 returns a bigger string something like this
m/94hAkh/PJsiE5opDAHv50rsRbh35l//opROfwdGH+XbBlXmhOEFKESvC45Ag66apJJqA==
The problem might be in the key... how ever changing the key will need a migrate process.
what do you advise?
Beta Was this translation helpful? Give feedback.
All reactions