|
| 1 | +# API |
| 2 | + |
| 3 | +## `hmac` |
| 4 | + |
| 5 | +Exposes an interface to the Keyed-Hash Message Authentication Code (HMAC) as defined in U.S. Federal Information Processing Standards Publication 198. An HMAC is a cryptographic hash that uses a key to sign a message. The receiver verifies the hash by recomputing it using the same key. |
| 6 | + |
| 7 | +### `create(hash, secret, callback)` |
| 8 | + |
| 9 | +- `hash: String` |
| 10 | +- `secret: Buffer` |
| 11 | +- `callback: Function` |
| 12 | + |
| 13 | +#### `digest(data, callback)` |
| 14 | + |
| 15 | +- `data: Buffer` |
| 16 | +- `callback: Function` |
| 17 | + |
| 18 | +## `aes` |
| 19 | +Expoes an interface to AES encryption (formerly Rijndael), as defined in U.S. Federal Information Processing Standards Publication 197. |
| 20 | + |
| 21 | +This uses `CTR` mode. |
| 22 | + |
| 23 | +### `create(key, iv, callback)` |
| 24 | + |
| 25 | +- `key: Buffer` The key, if length `16` then `AES 128` is used. For length `32`, `AES 256` is used. |
| 26 | +- `iv: Buffer` Must have length `16`. |
| 27 | +- `callback: Function` |
| 28 | + |
| 29 | +#### `encrypt(data, callback)` |
| 30 | + |
| 31 | +- `data: Buffer` |
| 32 | +- `callback: Function` |
| 33 | + |
| 34 | +#### `encrypt(data, callback)` |
| 35 | + |
| 36 | +- `data: Buffer` |
| 37 | +- `callback: Function` |
| 38 | + |
| 39 | + |
| 40 | +## `webcrypto` |
| 41 | + |
| 42 | +Depending on the environment this is either an instance of [node-webcrypto-ossl](https://github.com/PeculiarVentures/node-webcrypto-ossl) or the result of `window.crypto`. |
| 43 | + |
| 44 | +## `keys` |
| 45 | + |
| 46 | +## `generateKeyPair(type, bits, callback)` |
| 47 | + |
| 48 | +- `type: String`, only `'RSA'` is currently supported |
| 49 | +- `bits: Number` Minimum of 1024 |
| 50 | +- `callback: Function` |
| 51 | + |
| 52 | +Generates a keypair of the given type and bitsize. |
| 53 | + |
| 54 | +## `generateEphemeralKeyPair(curve, callback)` |
| 55 | + |
| 56 | +- `curve: String`, one of `'P-256'`, `'P-384'`, `'P-521'` is currently supported |
| 57 | +- `callback: Function` |
| 58 | + |
| 59 | +Generates an ephemeral public key and returns a function that will compute the shared secret key. |
| 60 | + |
| 61 | +Focuses only on ECDH now, but can be made more general in the future. |
| 62 | + |
| 63 | +Calls back with an object of the form |
| 64 | + |
| 65 | +```js |
| 66 | +{ |
| 67 | + key: Buffer, |
| 68 | + genSharedKey: Function |
| 69 | +} |
| 70 | +``` |
| 71 | + |
| 72 | +## `keyStretcher(cipherType, hashType, secret, callback)` |
| 73 | + |
| 74 | +- `cipherType: String`, one of `'AES-128'`, `'AES-256'`, `'Blowfish'` |
| 75 | +- `hashType: String`, one of `'SHA1'`, `SHA256`, `SHA512` |
| 76 | +- `secret: Buffer` |
| 77 | +- `callback: Function` |
| 78 | + |
| 79 | +Generates a set of keys for each party by stretching the shared key. |
| 80 | + |
| 81 | +Calls back with an object of the form |
| 82 | +```js |
| 83 | +{ |
| 84 | + k1: { |
| 85 | + iv: Buffer, |
| 86 | + cipherKey: Buffer, |
| 87 | + macKey: Buffer |
| 88 | + }, |
| 89 | + k2: { |
| 90 | + iv: Buffer, |
| 91 | + cipherKey: Buffer, |
| 92 | + macKey: Buffer |
| 93 | + } |
| 94 | +} |
| 95 | +``` |
| 96 | +## `marshalPublicKey(key[, type], callback)` |
| 97 | + |
| 98 | +- `key: crypto.rsa.RsaPublicKey` |
| 99 | +- `type: String`, only `'RSA'` is currently supported |
| 100 | + |
| 101 | +Converts a public key object into a protobuf serialized public key. |
| 102 | + |
| 103 | +## `unmarshalPublicKey(buf)` |
| 104 | + |
| 105 | +- `buf: Buffer` |
| 106 | + |
| 107 | +Converts a protobuf serialized public key into its representative object. |
| 108 | + |
| 109 | +## `marshalPrivateKey(key[, type])` |
| 110 | + |
| 111 | +- `key: crypto.rsa.RsaPrivateKey` |
| 112 | +- `type: String`, only `'RSA'` is currently supported |
| 113 | + |
| 114 | +Converts a private key object into a protobuf serialized private key. |
| 115 | + |
| 116 | +## `unmarshalPrivateKey(buf, callback)` |
| 117 | + |
| 118 | +- `buf: Buffer` |
| 119 | +- `callback: Function` |
| 120 | + |
| 121 | +Converts a protobuf serialized private key into its representative object. |
0 commit comments