JSLib Reference Manual / Exports / SBCrypto
Class: SBCrypto#
SBCrypto
SBCrypto contains all the SB specific crypto functions, as well as some general utility functions.
Table of contents#
Constructors#
Methods#
Constructors#
constructor#
• new SBCrypto()
Methods#
ab2str#
▸ ab2str(buffer): string
Standardized ‘ab2str()’ function, array buffer to string. This assumes one byte per character.
Parameters#
Name |
Type |
|---|---|
|
|
Returns#
string
string
compareKeys#
▸ compareKeys(key1, key2): boolean
SBCrypto.compareKeys()
Compare JSON keys, true if the ‘same’, false if different.
Parameters#
Name |
Type |
|---|---|
|
|
|
|
Returns#
boolean
deriveKey#
▸ deriveKey(privateKey, publicKey, type, extractable, keyUsages): Promise<CryptoKey>
SBCrypto.deriveKey()
Derive key.
Parameters#
Name |
Type |
|---|---|
|
|
|
|
|
|
|
|
|
|
Returns#
Promise<CryptoKey>
encrypt#
▸ encrypt(data, key, _iv?, returnType?): Promise<EncryptedContents>
SBCrypto.encrypt()
Encrypt. if no nonce (iv) is given, will create it. Returns a Promise that resolves either to raw array buffer or a packaged EncryptedContents. Note that for the former, nonce must be given.
Parameters#
Name |
Type |
|---|---|
|
|
|
|
|
|
|
|
Returns#
Promise<EncryptedContents>
▸ encrypt(data, key, _iv?, returnType?): Promise<ArrayBuffer>
Parameters#
Name |
Type |
|---|---|
|
|
|
|
|
|
|
|
Returns#
Promise<ArrayBuffer>
extractPubKey#
▸ extractPubKey(privateKey): null | JsonWebKey
Extracts (generates) public key from a private key.
Parameters#
Name |
Type |
|---|---|
|
|
Returns#
null | JsonWebKey
generateIdKey#
▸ generateIdKey(buf): Promise<{ id: string ; key: string }>
Hashes and splits into two (h1 and h1) signature of data, h1 is used to request (salt, iv) pair and then h2 is used for encryption (h2, salt, iv)
Parameters#
Name |
Type |
Description |
|---|---|---|
|
|
blob of data to be stored |
Returns#
Promise<{ id: string ; key: string }>
generateKeys#
▸ generateKeys(): Promise<CryptoKeyPair>
SBCrypto.generatekeys()
Generates standard ECDH keys using P-384.
Returns#
Promise<CryptoKeyPair>
importKey#
▸ importKey(format, key, type, extractable, keyUsages): Promise<CryptoKey>
SBCrypto.importKey()
Import keys
Parameters#
Name |
Type |
|---|---|
|
|
|
|
|
|
|
|
|
|
Returns#
Promise<CryptoKey>
sign#
▸ sign(secretKey, contents): Promise<string>
SBCrypto.sign()
Sign
Parameters#
Name |
Type |
|---|---|
|
|
|
|
Returns#
Promise<string>
str2ab#
▸ str2ab(string): Uint8Array
Standardized ‘str2ab()’ function, string to array buffer. This assumes on byte per character.
Parameters#
Name |
Type |
|---|---|
|
|
Returns#
Uint8Array
buffer
unwrap#
▸ unwrap(k, o, returnType): Promise<string>
SBCrypto.unwrap
Decrypts a wrapped object, returns (promise to) decrypted contents per se (either as a string or arrayBuffer)
Parameters#
Name |
Type |
|---|---|
|
|
|
|
|
|
Returns#
Promise<string>
▸ unwrap(k, o, returnType): Promise<ArrayBuffer>
Parameters#
Name |
Type |
|---|---|
|
|
|
|
|
|
Returns#
Promise<ArrayBuffer>
verify#
▸ verify(verifyKey, sign, contents): Promise<boolean>
SBCrypto.verify()
Verify signature.
Parameters#
Name |
Type |
|---|---|
|
|
|
|
|
|
Returns#
Promise<boolean>
wrap#
▸ wrap(k, b, bodyType): Promise<EncryptedContents>
Parameters#
Name |
Type |
|---|---|
|
|
|
|
|
|
Returns#
Promise<EncryptedContents>
▸ wrap(k, b, bodyType): Promise<EncryptedContents>
Parameters#
Name |
Type |
|---|---|
|
|
|
|
|
|
Returns#
Promise<EncryptedContents>