phog
crypto functions for fognet and the web
phog uses the Web Crypto API and base 58 encoding
open test.html in any browser to test
phog configs
const configs = sign: algo: name: 'ECDSA' namedCurve: 'P-256' usage: 'sign' 'verify' format: public:'spki' private:'pkcs8' derive: algo: name:'ECDH' namedCurve:'P-256' usage: 'deriveKey' format: public:'spki' private:'pkcs8' encrypt: algo: name:'AES-GCM' length: 256 usage: 'encrypt' 'decrypt' format: public:'raw' private:'raw' windowcrypto
api
keyGen (object)
Generate a key (returns a CryptoKey pair)
const key = await phog // for signingconst key = await phog // for deriving shared keys// returns { publicKey:CryptoKey{}, privateKey:CryptoKey{} }
sign (string, CryptoKey)
Sign some text (returns base58-encoded signature string)
const sig = await phog
verify (string, string, CryptoKey)
Verify a signature (returns a bool)
const verified = await phog
deriveKey (CryptoKey, CryptoKey)
Derive a shared symmetric key from your private key and another person's public key. (returns a CryptoKey)
const secret = await phog
encrypt (string, CryptoKey)
Symmetrically encrypt some data (returns a base58-encoded string)
const encrypted = await phog
decrypt (string, CryptoKey)
Decrypt some data (returns a string)
const decrypted = await phog
exportKey (CryptoKey, object, string)
Export a public key to base58:
const keyString = await phog
To export a private key, you must specify 'private' as the last argument:
const keyString = await phog
importKey (string, object, string)
Import a base58-encoded public key (returns a CryptoKey)
const key = await phog