Secrets.Secret_boxEncrypted secrets.
of_yojson is the only constructor that takes in raw data. General usage pattern:
let protected = Secret_box.encrypt ~password ~plaintext |> Secret_box.to_yojson |> Yojson.to_string in
let maybe_unprotected = Secret_box.of_yojson protected |> Or_error.map ~f:(Secret_box.decrypt ~password) in
assert maybe_unprotected = Ok plaintextNOTE: this will _erase_ the contents of password arguments. If you stash them somewhere (you shouldn't outside of tests), you should copy the string before you call these functions.
val to_yojson : t -> Yojson.Safe.tval of_yojson : Yojson.Safe.t -> t Ppx_deriving_yojson_runtime.error_orval encrypt :
password:Core_kernel.Bytes.t ->
plaintext:Core_kernel.Bytes.t ->
tPassword-protect some plaintext.
val decrypt :
password:Core_kernel.Bytes.t ->
t ->
( Core_kernel.Bytes.t,
[> `Corrupted_privkey of Core_kernel.Error.t
| `Incorrect_password_or_corrupted_privkey ] )
Core_kernel.Result.tDecrypt some bytes with a password