Dcrypt\Otp::crypt PHP Method

crypt() public static method

Encrypt or decrypt a binary input string.
public static crypt ( string $input, string $password, string $algo = 'sha512' ) : string
$input string Input data to encrypt
$password string Encryption/decryption key to use on input
$algo string Hashing algo to generate keystream
return string
    public static function crypt($input, $password, $algo = 'sha512')
    {
        $chunks = \str_split($input, Str::hashSize($algo));
        foreach ($chunks as $i => &$chunk) {
            $chunk = $chunk ^ \hash($algo, $password . $i, true);
        }
        return \implode($chunks);
    }

Usage Example

Beispiel #1
0
 public function testVector()
 {
     $input = 'hello world';
     $pass = '******';
     $vector = base64_decode('vusXragCy83KQFo');
     $this->assertEquals($input, Otp::crypt($vector, $pass));
 }