You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+117-48
Original file line number
Diff line number
Diff line change
@@ -50,24 +50,27 @@ This library is still in active development and all algorithms are not yet suppo
50
50
51
51
## Algorithms
52
52
53
-
When passing algorithms params into subtle functions, we use the `webcrypto.Algorithm` struct. It has the following properties:
53
+
When passing algorithm params into subtle functions, we use the `webcrypto.Algorithm` struct. It has the following properties:
54
54
55
55
| Field | Type | Description |
56
56
| :---- | :--- | :---------- |
57
57
| Name |`string`| The algorithm name. |
58
58
| Params |`any`| The algorithm parameters as defined by the parameters described by that algorithm in the WebCrypto specification. |
59
59
60
-
For each algorithm and function described below, listed are the appropriate algorithm params that need to be passed in.
60
+
See specific algorithms for the parameter types to be passed in.
61
61
62
62
### ECDSA
63
63
64
-
The **ECDSA** algorithm is the implementation of operations described in [§23](https://www.w3.org/TR/WebCryptoAPI/#ecdsa) of the W3C specification.
64
+
The **ECDSA** algorithm is the implementation of operations described in [§23](https://www.w3.org/TR/WebCryptoAPI/#ecdsa) of the W3C specification. You can import it into your program with `import "github.com/armortal/webcrypto-go/algorithms/ecdsa"`.
65
65
66
66
#### Parameter Definitions
67
67
68
+
Below are the parameters that supported ECDSA operations will take according to
// do something with the imported webcrypto.CryptoKey
171
174
}
172
175
```
173
176
174
177
### HMAC
175
178
176
-
The **HMAC** algorithm is the implementation of operations described in [§29](https://www.w3.org/TR/WebCryptoAPI/#hmac) of the W3C specification.
179
+
The **HMAC** algorithm is the implementation of operations described in [§29](https://www.w3.org/TR/WebCryptoAPI/#hmac) of the W3C specification. You can import it into your program with `import "github.com/armortal/webcrypto-go/algorithms/hmac"`.
180
+
181
+
#### Parameter Definitions
182
+
183
+
Below are the parameters that supported HMAC operations will take according to
As specified in [§29.5](https://www.w3.org/TR/WebCryptoAPI/#hmac-keygen-params)
189
+
190
+
| Field | Type | Description |
191
+
| :---- | :--- | :---------- |
192
+
| Hash |`string`| The inner hash function to use. See the supported [hash algorithms](#hash-algorithms). |
193
+
| Length |`uint64`| The length (in bits) of the key to generate. If unspecified, the recommended length will be used, which is the size of the associated hash function's block size. |
194
+
195
+
###### ImportParams
196
+
197
+
As specified in [§29.3](https://www.w3.org/TR/WebCryptoAPI/#hmac-importparams)
198
+
199
+
| Field | Type | Description |
200
+
| :---- | :--- | :---------- |
201
+
| Hash |`string`| The inner hash function to use. See the supported [hash algorithms](#hash-algorithms). |
202
+
| Length |`uint64`| The length (in bits) of the key. |
203
+
204
+
#### Examples
177
205
178
206
```go
179
207
package main
@@ -184,61 +212,102 @@ import (
184
212
)
185
213
186
214
funcmain() {
187
-
//Generate a new key. A *hmac.CryptoKey is returned which implements webcrypto.CryptoKey
215
+
//generate a new key
188
216
key, err:= webcrypto.Subtle().GenerateKey(
189
-
&Algorithm{
190
-
Name: "ECDSA",
191
-
Params: ecdsa.KeyGenParams{
192
-
193
-
}
194
-
}
195
-
&hmac.Algorithm{
196
-
KeyGenParams: &hmac.KeyGenParams{
217
+
&webcrypto.Algorithm{
218
+
Name: "HMAC",
219
+
Params: &hmac.KeyGenParams{
197
220
Hash: "SHA-256",
198
221
},
199
-
}, true, webcrypto.Sign, webcrypto.Verify)
222
+
}, true, []webcrypto.KeyUsage{
223
+
webcrypto.Sign,
224
+
webcrypto.Verify,
225
+
})
200
226
227
+
if err != nil {
228
+
panic(err)
229
+
}
230
+
231
+
// the generated key returns a webcrypto.CryptoKey
201
232
cryptokey:= key.(webcrypto.CryptoKey)
202
233
203
-
// Sign some data. Note that this library uses io.Reader to pass bytes of data.
0 commit comments