Upstream version 9.37.197.0
[platform/framework/web/crosswalk.git] / src / third_party / trace-viewer / third_party / tvcm / third_party / Promises / reworked_APIs / WebCrypto / example / before.html
1 <!DOCTYPE html>
2 <html>
3   <head>
4     <title></title>
5     <script>
6       "use strict";
7
8       // Algorithm Object
9       var algorithmKeyGen = {
10         name: "RSASSA-PKCS1-v1_5",
11         params: {
12           modulusLength: 2048,
13           publicExponent: new Uint8Array([0x01, 0x00, 0x01]),  // Equivalent to 65537
14         }
15       };
16
17       var algorithmSign = {
18         name: "RSASSA-PKCS1-v1_5",
19         params: { hash: { name: "SHA-256" } }
20       };
21
22       var keyGen = this.crypto.generateKey(algorithmKeyGen, false, ["sign"]);
23
24       keyGen.oncomplete = function(event) {
25         // Because we are not supplying data to .sign(), a multi-part
26         // CryptoOperation will be returned, which requires us to call .process()
27         // and .finish().
28         var signer = window.crypt.sign(algorithmSign, event.target.result.privateKey);
29         signer.oncomplete = function(event) {
30           console.log("The signature is: " + event.target.result);
31         }
32         signer.onerror = function(event) {
33           console.error("Unable to sign");
34         }
35
36         var dataPart1 = convertPlainTextToArrayBufferView("hello,");
37         var dataPart2 = convertPlainTextToArrayBufferView(" world!");
38         // TODO: create example utility function that converts text -> ArrayBufferView
39
40         signer.process(dataPart1);
41         signer.process(dataPart2);
42         signer.finish();
43       };
44
45       keyGen.onerror = function(event) {
46         console.error("Unable to generate a key.");
47       };
48
49     </script>
50   </head>
51   <body></body>
52 </html>