-
-
Save dinosaure/8c22efae8597f6b1640bd710f32398a6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(executable | |
(name main) | |
(libraries brr) | |
(modes js)) | |
(rule (copy main.bc.js main.js)) | |
(alias | |
(name app) | |
(deps main.js min.html)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open Brr | |
open Brr_webcrypto | |
open Fut.Result_syntax | |
let sym_key s = | |
let sym_key_gen = | |
let name = Crypto_algo.aes_cbc and length = 128 in | |
Crypto_algo.Aes_key_gen_params.v ~name ~length () in | |
let usages = Crypto_key.Usage.[ encrypt; decrypt ] in | |
Subtle_crypto.generate_key s sym_key_gen ~extractable:true ~usages | |
let main () = | |
let subtl = Crypto.subtle Crypto.crypto in | |
let* key = sym_key subtl in | |
let* key = Subtle_crypto.export_key subtl Crypto_key.Format.raw key in | |
let[@warning "-8"] (`Buffer key : [ `Buffer of _ | `Json_web_key of _ ]) = key in | |
Console.(debug [str "key: %s", (Tarray.to_hex_jstr key)]) ; | |
Fut.ok () | |
open Fut.Syntax | |
let main () = | |
Console.(debug [str "run"]) ; | |
let* res = main () in | |
match res with | |
| Ok () -> Fut.return () | |
| Error err -> | |
Console.(error [str "Got an error: %s"; Jv.Error.message err]) ; | |
Fut.return () | |
let () = ignore (main ()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<title>Web crypto</title> | |
<script type="text/javascript" defer="defer" src="main.js"></script> | |
</head> | |
<body><noscript>lol</noscript></body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment