1 | <?php |
||
17 | class SignedXml |
||
18 | { |
||
19 | /** |
||
20 | * @var SunatXmlSecAdapter |
||
21 | */ |
||
22 | private $adapter; |
||
23 | |||
24 | /** |
||
25 | * SignedXml constructor. |
||
26 | */ |
||
27 | 66 | public function __construct() |
|
31 | |||
32 | /** |
||
33 | * Firma el contenido del xml y retorna el contenido firmado. |
||
34 | * |
||
35 | * @param string $content |
||
36 | * @return string |
||
37 | */ |
||
38 | 42 | public function sign($content) |
|
39 | { |
||
40 | 42 | $doc = $this->getDocXml($content); |
|
41 | |||
42 | 42 | $this->adapter->sign($doc); |
|
43 | 42 | return $doc->saveXML(); |
|
44 | } |
||
45 | |||
46 | /** |
||
47 | * Verifica la firma del xml. |
||
48 | * |
||
49 | * @param string $content |
||
50 | * @return bool |
||
51 | */ |
||
52 | 2 | public function verify($content) |
|
53 | { |
||
54 | 2 | $doc = $this->getDocXml($content); |
|
55 | 2 | $this->adapter->getPublicKey($doc); |
|
56 | |||
57 | 2 | return $this->adapter->verify($doc); |
|
58 | } |
||
59 | |||
60 | /** |
||
61 | * @param string $cert |
||
62 | */ |
||
63 | 62 | public function setCertificate($cert) |
|
64 | { |
||
65 | 62 | $this->adapter->setPrivateKey($cert); |
|
66 | 62 | $this->adapter->setPublicKey($cert); |
|
67 | 62 | } |
|
68 | |||
69 | /** |
||
70 | * @param string $content |
||
71 | * @return \DOMDocument |
||
72 | */ |
||
73 | 42 | private function getDocXml($content) |
|
80 | } |