"1111", "VK_VERSION" => "008", "VK_SND_ID" => "HP", "VK_REC_ID" => "uid100052", "VK_STAMP" => "4321", "VK_T_NO" => "10146", "VK_AMOUNT" => "20.00", "VK_CURR" => "EUR", "VK_REC_ACC" => "", "VK_REC_NAME" => "", "VK_SND_ACC" => "EE152200221234567897", "VK_SND_NAME" => "Tõõger Leõpäöld", "VK_REF" => "43216", "VK_MSG" => "Vaheajatellimus 2304170001 20.04.2023 19:00", "VK_T_DATETIME" => "2023-04-17T12:12:56+0000", "VK_ENCODING" => "UTF-8", "VK_LANG" => "EST", "VK_MAC" => "jXj85D2Xq1c42MjhdtohCm1xiM+ZlVjWw9NvFIWwWwViDm4gSOFfIY7yjZDA0miWAj4Vj44lXsc3K/KmLHQlAFrlU/Dauh7DXxg6skoin/rLT+l+3Cq2jhlHjtN27Q9yS7GeQUeT+tq3mI3J/Z1dRFNdVSrga51J2Jix/WOnf3mn7RyOeGky7umpwF2KiZ2q+1Fznc3yuesSFfFq2BeqflN7q+5pepk4NyIL8mk/VbS37P6VxSoN3RrY4X2iwr5jKRfXmUijAZTwgcVwqad9HqyxRdx39l2cGEn9u130oud01H/nIuEXlZhtnqudJen9pYaICzYlbg+0tM5thpOvJQ==", "VK_AUTO" => "N" ); // STEP 3. Generate data to be verified // ==================================== // Data to be verified is in the form of XXXYYYYY where XXX is 3 char // zero padded length of the value and YYY the value itself // NB! Swedbank expects symbol count, not byte count with UTF-8, // so use `mb_strlen` instead of `strlen` to detect the length of a string $data = str_pad (mb_strlen($fields["VK_SERVICE"], "UTF-8"), 3, "0", STR_PAD_LEFT) . $fields["VK_SERVICE"] . /* 1111 */ str_pad (mb_strlen($fields["VK_VERSION"], "UTF-8"), 3, "0", STR_PAD_LEFT) . $fields["VK_VERSION"] . /* 008 */ str_pad (mb_strlen($fields["VK_SND_ID"], "UTF-8"), 3, "0", STR_PAD_LEFT) . $fields["VK_SND_ID"] . /* HP */ str_pad (mb_strlen($fields["VK_REC_ID"], "UTF-8"), 3, "0", STR_PAD_LEFT) . $fields["VK_REC_ID"] . /* uid100052 */ str_pad (mb_strlen($fields["VK_STAMP"], "UTF-8"), 3, "0", STR_PAD_LEFT) . $fields["VK_STAMP"] . /* 4321 */ str_pad (mb_strlen($fields["VK_T_NO"], "UTF-8"), 3, "0", STR_PAD_LEFT) . $fields["VK_T_NO"] . /* 10146 */ str_pad (mb_strlen($fields["VK_AMOUNT"], "UTF-8"), 3, "0", STR_PAD_LEFT) . $fields["VK_AMOUNT"] . /* 20.00 */ str_pad (mb_strlen($fields["VK_CURR"], "UTF-8"), 3, "0", STR_PAD_LEFT) . $fields["VK_CURR"] . /* EUR */ str_pad (mb_strlen($fields["VK_REC_ACC"], "UTF-8"), 3, "0", STR_PAD_LEFT) . $fields["VK_REC_ACC"] . /* */ str_pad (mb_strlen($fields["VK_REC_NAME"], "UTF-8"), 3, "0", STR_PAD_LEFT) . $fields["VK_REC_NAME"] . /* */ str_pad (mb_strlen($fields["VK_SND_ACC"], "UTF-8"), 3, "0", STR_PAD_LEFT) . $fields["VK_SND_ACC"] . /* EE152200221234567897 */ str_pad (mb_strlen($fields["VK_SND_NAME"], "UTF-8"), 3, "0", STR_PAD_LEFT) . $fields["VK_SND_NAME"] . /* Tõõger Leõpäöld */ str_pad (mb_strlen($fields["VK_REF"], "UTF-8"), 3, "0", STR_PAD_LEFT) . $fields["VK_REF"] . /* 43216 */ str_pad (mb_strlen($fields["VK_MSG"], "UTF-8"), 3, "0", STR_PAD_LEFT) . $fields["VK_MSG"] . /* Vaheajatellimus 2304170001 20.04.2023 19:00 */ str_pad (mb_strlen($fields["VK_T_DATETIME"], "UTF-8"), 3, "0", STR_PAD_LEFT) . $fields["VK_T_DATETIME"]; /* 2023-04-17T12:12:56+0000 */ /* $data = "0041111003008002HP009uid10005200443210051014600520.00003EUR000000020EE152200221234567897015Tõõger Leõpäöld00543216043Vaheajatellimus 2304170001 20.04.2023 19:000242023-04-17T12:12:56+0000"; */ // STEP 4. Verify the data with RSA-SHA1 // ===================================== if (openssl_verify ($data, base64_decode($fields["VK_MAC"]), $public_key) !== 1) { $signatureVerified = false; }else{ $signatureVerified = true; } // STEP 5. Display output of the received payment // ============================================== ?>

Payment results

Payment:

Signature: