Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
 
3
namespace Laravel\SerializableClosure\Signers;
4
 
5
use Laravel\SerializableClosure\Contracts\Signer;
6
 
7
class Hmac implements Signer
8
{
9
    /**
10
     * The secret key.
11
     *
12
     * @var string
13
     */
14
    protected $secret;
15
 
16
    /**
17
     * Creates a new signer instance.
18
     *
19
     * @param  string  $secret
20
     * @return void
21
     */
22
    public function __construct($secret)
23
    {
24
        $this->secret = $secret;
25
    }
26
 
27
    /**
28
     * Sign the given serializable.
29
     *
30
     * @param  string  $serialized
31
     * @return array
32
     */
33
    public function sign($serialized)
34
    {
35
        return [
36
            'serializable' => $serialized,
37
            'hash' => base64_encode(hash_hmac('sha256', $serialized, $this->secret, true)),
38
        ];
39
    }
40
 
41
    /**
42
     * Verify the given signature.
43
     *
44
     * @param  array  $signature
45
     * @return bool
46
     */
47
    public function verify($signature)
48
    {
49
        return hash_equals(base64_encode(
50
            hash_hmac('sha256', $signature['serializable'], $this->secret, true)
51
        ), $signature['hash']);
52
    }
53
}