Upstream version 5.34.98.0
[platform/framework/web/crosswalk.git] / src / third_party / trace-viewer / third_party / Promises / reworked_APIs / WebCrypto / example / after.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 crypto = this.crypto;
23
24       crypto.generateKey(algorithmKeyGen, false, ["sign"]).
25         then(
26           function(result) {
27             // Because we are not supplying data to .sign(), a multi-part
28             // CryptoOperation will be returned, which requires us to call
29             // .process() and .finish(), both of which return futures. We return
30             // the future for the eventual finished operation.
31             return crypto.sign(algorithmSign, result.privateKey).
32               process(convertPlainTextToArrayBufferView("hello,")).
33               process(convertPlainTextToArrayBufferView(" world!")).
34               finish();
35           },
36           function(err) { console.error("Unable to generate a key."); }
37         ).
38         then(
39           function(result) { console.log("The signature is: ", result); }
40           function(err) {console.error("Unable to sign:", err); }
41         );
42     </script>
43   </head>
44   <body></body>
45 </html>