Skip to content

Repository files navigation

sec.js

日本語のREADMEはこちらです: README.ja.md

  • sec.js is a library for key generation, digital signatures, key agreement, and encryption/decryption using Curve25519 (Ed25519 / X25519).
  • sec.js は、Curve25519(Ed25519 / X25519)を利用した鍵生成・電子署名・鍵共有・暗号化/復号のためのライブラリです。

sign / verify

import*assecfrom"https://code4fukui.github.io/sec.js/sec.js";// 秘密鍵constprikey1=sec.prikey();// or new Uint8Array(32) の乱数crypto.getRandomValues(prikey);// 秘密鍵を元に公開鍵(32byte)を作成constpubkey=sec.pubkey(prikey);// 秘密鍵で電子署名するconstmessage=newTextEncoder().encode("Hello!");constsign=sec.sign(prikey,message);// 公開鍵から電子署名を検証するalert("VERIFIED:"+sec.verify(sign,pubkey,message));

sharekey / encrypt / decrypt

import*assecfrom"https://code4fukui.github.io/sec.js/sec.js";// ユーザー1constprikey1=sec.prikey();constpubkey1=sec.pubkey(prikey1);console.log(pubkey1,prikey1);// ユーザー2constprikey2=sec.prikey();constpubkey2=sec.pubkey(prikey2);console.log(pubkey2,prikey2);// 相手の公開鍵と自分の秘密から共通鍵を生成、一致しているconstshare1=sec.sharekey(prikey1,pubkey2);constshare2=sec.sharekey(prikey2,pubkey1);console.log("sherekey",share1,share2);// 暗号化constdata=newTextEncoder().encode("abc");constcipher=sec.encrypt(share1,data);console.log(cipher);// 複合化constdec=sec.decrypt(share1,cipher);console.log(newTextDecoder().decode(dec));

test

deno test --allow-import=code4fukui.github.io,deno.land sec.test.js

dependencies

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages