1 | <html> |
---|
2 | <head> |
---|
3 | <script type="text/javascript" src="jquery.min.js"></script> |
---|
4 | <script type="text/javascript" src="gitversion.js"></script> |
---|
5 | <script type="text/javascript" src="hwcrypto-legacy.js"></script> |
---|
6 | <script type="text/javascript" src="hwcrypto.js"></script> |
---|
7 | <script type="text/javascript" src="hex2base.js"></script> |
---|
8 | <script type="text/javascript" src="jquery.min.js"></script> |
---|
9 | <script type="text/javascript"> |
---|
10 | |
---|
11 | function SignFilePDF() { |
---|
12 | |
---|
13 | var fileInput = document.getElementById("file-sign"); |
---|
14 | var list = fileInput.files; |
---|
15 | var form = $('firmar')[0]; |
---|
16 | var data = new FormData(); |
---|
17 | data.append('upload', $("#file-sign")[0].files[0]); |
---|
18 | |
---|
19 | $.ajax({ |
---|
20 | url: "https://murachi.cenditel.gob.ve/Murachi/0.1/archivos", |
---|
21 | type: "post", |
---|
22 | dataType: "json", |
---|
23 | data: data, |
---|
24 | cache: false, |
---|
25 | contentType: false, |
---|
26 | processData: false, |
---|
27 | xhrFields: {withCredentials: true}, |
---|
28 | headers: {"Authorization":"Basic YWRtaW46YWRtaW4="}, |
---|
29 | success: function(response) { |
---|
30 | var responseString = JSON.stringify(response); |
---|
31 | document.getElementById("seccion1").innerHTML = responseString; |
---|
32 | var fileId = response.fileId.toString(); |
---|
33 | var cert; |
---|
34 | |
---|
35 | window.hwcrypto.getCertificate({lang: "en"}).then(function(response) { |
---|
36 | var cert = response; |
---|
37 | var parameters = JSON.stringify({ |
---|
38 | "fileId":fileId, |
---|
39 | "certificate":cert.hex, |
---|
40 | "reason":"Certificado", |
---|
41 | "location":"CENDITEL", |
---|
42 | "contact":"582746574336", |
---|
43 | "signatureVisible":"true" |
---|
44 | }); |
---|
45 | $.ajax({ |
---|
46 | type: 'POST', |
---|
47 | contentType: 'application/json', |
---|
48 | url:"https://murachi.cenditel.gob.ve/Murachi/0.1/archivos/pdfs", |
---|
49 | dataType: "json", |
---|
50 | data: parameters, |
---|
51 | xhrFields: {withCredentials: true}, |
---|
52 | headers: {"Authorization":"Basic YWRtaW46YWRtaW4="}, |
---|
53 | success: function(data, textStatus, jqXHR) { |
---|
54 | var responseString = JSON.stringify(data); |
---|
55 | document.getElementById("seccion2").innerHTML = responseString; |
---|
56 | |
---|
57 | var json_x = data; |
---|
58 | var hash = json_x['hash']; |
---|
59 | alert("hash recibido del servidor "+hash); |
---|
60 | var hashtype = "SHA-256"; |
---|
61 | var lang = "eng"; |
---|
62 | |
---|
63 | window.hwcrypto.sign(cert, {type: hashtype, hex: hash}, {lang: lang}).then(function(signature) { |
---|
64 | |
---|
65 | $.ajax({ |
---|
66 | type: 'POST', |
---|
67 | contentType: 'application/json', |
---|
68 | url:"https://murachi.cenditel.gob.ve/Murachi/0.1/archivos/pdfs/resenas", |
---|
69 | dataType: 'json', |
---|
70 | data: JSON.stringify({"signature":signature.hex}), |
---|
71 | xhrFields: {withCredentials: true}, |
---|
72 | headers: {"Authorization":"Basic YWRtaW46YWRtaW4="}, |
---|
73 | success: function(data, textStatus, jqXHR){ |
---|
74 | console.log(data); |
---|
75 | var responseString = JSON.stringify(data); |
---|
76 | document.getElementById("seccion3").innerHTML = responseString; |
---|
77 | alert('Archivo firmado correctamente: ' + data['signedFileId']); |
---|
78 | document.getElementById("seccion4").innerHTML = "Descargar archivo firmado: https://murachi.cenditel.gob.ve/Murachi/0.1/archivos/descargas/" + data['signedFileId']; |
---|
79 | } // repuesta del ajax 3 |
---|
80 | }) //ajax 3 |
---|
81 | }) //windowhwcrypto.sign() |
---|
82 | } // respuesta ajax 2 |
---|
83 | }) //ajax 2 |
---|
84 | }) //windowhwcrypto.getCertificate() |
---|
85 | } // respuesta ajax 1 |
---|
86 | }) //ajax 1 |
---|
87 | } |
---|
88 | |
---|
89 | |
---|
90 | </script> |
---|
91 | </head> |
---|
92 | <body> |
---|
93 | |
---|
94 | <form enctype="multipart/form-data" action="javaScript:SignFilePDF()" method="post" id="firmar" name="SignFormat"> |
---|
95 | <h2>Firmar electrónica (PDF)</h2> |
---|
96 | <h3>Seleccione el archivo que va a firmar electrónicamente</h2> |
---|
97 | <br> |
---|
98 | <input id="file-sign" class="file" type="file" data-min-file-count="1" name="upload" accept=".pdf" > |
---|
99 | <br> |
---|
100 | <br> |
---|
101 | <button type="submit" class="btn btn-primary">Enviar</button> |
---|
102 | <button type="reset" id="reset" class="btn btn-default">Limpiar</button> |
---|
103 | <br> |
---|
104 | <br> |
---|
105 | <div id="seccion1"> </div> |
---|
106 | <br> |
---|
107 | <div id="seccion2"> </div> |
---|
108 | <br> |
---|
109 | <div id="seccion3"> </div> |
---|
110 | <br> |
---|
111 | <div id="seccion4"> </div> |
---|
112 | </form> |
---|
113 | </body> |
---|
114 | </html> |
---|
115 | |
---|
116 | |
---|