bjosodium: libsodium's authenticated encryption and Argon2id for Bjolang
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
911f4bcc46
9 changed files with 1409 additions and 0 deletions
24
examples/vault.bjo
Normal file
24
examples/vault.bjo
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
;; bjosodium/examples/vault.bjo — the example of the Readme.
|
||||
;;
|
||||
;; bjo run examples/vault.bjo
|
||||
|
||||
(import (std prelude))
|
||||
(import (bjosodium core))
|
||||
|
||||
(defun (main)
|
||||
;; A key from a password. Store the salt and the cost beside the data.
|
||||
(def salt (make-argon2id-salt))
|
||||
(def key (argon2id-derive-key "correct horse" salt))
|
||||
|
||||
;; Encrypt. The header is not secret, but a change to it is found.
|
||||
(def cipher (preferred-cipher))
|
||||
(def header (string->bytes "bookmarks v1"))
|
||||
(def sealed (aead-seal cipher key (string->bytes "https://example.org") #:aad header))
|
||||
|
||||
(match (aead-unseal cipher key sealed #:aad header)
|
||||
((Some plaintext) (println (bytes->string plaintext)) 0)
|
||||
(None (println "wrong key, or the data was changed") 1)))
|
||||
Loading…
Add table
Add a link
Reference in a new issue