From f4bf78cb1ed4ef28aebc820d9ae68dc0b292cd65 Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Tue, 13 Aug 2019 23:09:51 +0200 Subject: [PATCH] fix seed encrypting --- src/Application/Model/d3totp.php | 2 +- src/tests/unit/Application/Model/d3totpTest.php | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Application/Model/d3totp.php b/src/Application/Model/d3totp.php index 94576a5..c255de3 100644 --- a/src/Application/Model/d3totp.php +++ b/src/Application/Model/d3totp.php @@ -251,7 +251,7 @@ class d3totp extends BaseModel $iv = openssl_random_pseudo_bytes($ivlen); $ciphertext_raw = openssl_encrypt($plaintext, $cipher, $key, $options=OPENSSL_RAW_DATA, $iv); $hmac = hash_hmac('sha256', $ciphertext_raw, $key, $as_binary=true); - return $this->d3Base64_decode($iv.$hmac.$ciphertext_raw); + return base64_encode($iv.$hmac.$ciphertext_raw); } /** diff --git a/src/tests/unit/Application/Model/d3totpTest.php b/src/tests/unit/Application/Model/d3totpTest.php index 2d2be83..ce3dbc3 100644 --- a/src/tests/unit/Application/Model/d3totpTest.php +++ b/src/tests/unit/Application/Model/d3totpTest.php @@ -732,8 +732,11 @@ class d3totpTest extends d3TotpUnitTestCase { $sReturn = $this->callMethod($this->_oModel, 'encrypt', ['foobar']); + // indirect tests, because string changes on every call $this->assertInternalType('string', $sReturn); $this->assertNotSame('foobar', $sReturn); + $this->assertStringEndsWith('==', $sReturn); + $this->assertTrue(strlen($sReturn) === 88); } /**