Как можно конвертировать PHP метод psha1 в JAVA - PullRequest
0 голосов
/ 10 апреля 2020

Мне нужно преобразовать PHP метод psha1 в JAVA.

Метод на PHP:

protected function psha1($clientSecret, $serverSecret, $sizeBits = 256)
    {
        $sizeBytes = $sizeBits / 8;

        $hmacKey = $clientSecret;

        $i = 0;

        $b1 = $serverSecret;
        $b2 = "";
        $temp = null;
        $psha = array();

        while ($i < $sizeBytes) {
            $b1 = hash_hmac('SHA1', $b1, $hmacKey, true);
            $b2 = $b1 . $serverSecret;
            $temp = hash_hmac('SHA1', $b2, $hmacKey, true);

            for ($j = 0; $j < strlen($temp); $j++) {
                if ($i < $sizeBytes) {
                    $psha[$i] = $temp[$j];
                    $i++;
                } else {
                    break;
                }
            }
        }

        return implode("", $psha);
    }

Помогите, пожалуйста.

Я не понимаю, что происходит внутри l oop.

...