2
2
3
3
An implementation of the W3C Web Cryptography API specification (https://www.w3.org/TR/WebCryptoAPI/ ) for Go using Go's standard ` crypto ` library.
4
4
5
+ > [ !IMPORTANT]
6
+ > Whilst we try to ensure that we don't commit breaking changes until we release our first stable version, there
7
+ > may be times where decisions made during early development no longer make sense and therefore require
8
+ > breaking changes. Please be mindful of this when updating your version of this library until we hit v1.0.0.
9
+
5
10
## Contents
6
11
7
12
- [ Background] ( #background )
8
13
- [ Implementation status] ( #implementation-status )
9
14
- [ Getting started] ( #getting-started )
10
15
- [ Algorithms] ( #algorithms )
16
+ - [ECDSA](#ecdsa)
11
17
- [HMAC](#hmac)
12
18
- [RSA-OAEP](#rsa-oaep)
13
19
- [SHA](#sha)
@@ -29,6 +35,7 @@ This library is still in active development and all algorithms are not yet suppo
29
35
30
36
| Algorithm | encrypt | decrypt | sign | verify | digest | generateKey | deriveKey | deriveBits | importKey | exportKey | wrapKey | unwrapKey |
31
37
| :--: | :--: | :--: | :--: | :--: | :--: | :--: | :--: | :--: | :--: | :--: | :--: | :--: |
38
+ | [ ECDSA] ( #ecdsa ) ||| :white_check_mark : | :white_check_mark : || :white_check_mark : ||| :white_check_mark : | :white_check_mark : |||
32
39
| [ HMAC] ( #hmac ) ||| :white_check_mark : | :white_check_mark : || :white_check_mark : ||| :white_check_mark : | :white_check_mark : |||
33
40
| [ RSA-OAEP] ( #rsa-oaep ) | :white_check_mark : | :white_check_mark : |||| :white_check_mark : ||| :white_check_mark : | :white_check_mark : |||
34
41
| [ SHA] ( #sha ) ||||| :white_check_mark : ||||||||
@@ -39,6 +46,52 @@ This library is still in active development and all algorithms are not yet suppo
39
46
40
47
## Algorithms
41
48
49
+ ### ECDSA
50
+
51
+ The ** ECDSA** algorithm is the implementation of operations described in [ §23] ( https://www.w3.org/TR/WebCryptoAPI/#ecdsa ) of the W3C specification.
52
+
53
+ ``` go
54
+ package main
55
+
56
+ import (
57
+ " github.com/armortal/webcrypto-go"
58
+ " github.com/armortal/webcrypto-go/algorithms/ecdsa"
59
+ )
60
+
61
+ func main () {
62
+ // generate a new ECDSA key
63
+ key , err := webcrypto.Subtle ().GenerateKey (
64
+ &ecdsa.Algorithm {
65
+ NamedCurve: " P-256" ,
66
+ }, true , webcrypto.Sign , webcrypto.Verify )
67
+ if err != nil {
68
+ panic (err)
69
+ }
70
+
71
+ ckp := key.(webcrypto.CryptoKeyPair )
72
+
73
+ // sign some data with the private key
74
+ sig , err := webcrypto.Subtle ().Sign (&ecdsa.Algorithm {
75
+ Hash: " SHA-256" ,
76
+ }, ckp.PrivateKey (), []byte (" test" ))
77
+ if err != nil {
78
+ panic (err)
79
+ }
80
+
81
+ // verify the signature with the public key
82
+ ok , err := webcrypto.Subtle ().Verify (&ecdsa.Algorithm {
83
+ Hash: " SHA-256" ,
84
+ }, ckp.PublicKey (), sig, []byte (" test" ))
85
+ if err != nil {
86
+ panic (err)
87
+ }
88
+
89
+ if !ok {
90
+ // didn't verify - do something
91
+ }
92
+ }
93
+ ```
94
+
42
95
### HMAC
43
96
44
97
The ** HMAC** algorithm is the implementation of operations described in [ §29] ( https://www.w3.org/TR/WebCryptoAPI/#hmac ) of the W3C specification.
@@ -54,6 +107,12 @@ import (
54
107
func main () {
55
108
// Generate a new key. A *hmac.CryptoKey is returned which implements webcrypto.CryptoKey
56
109
key , err := webcrypto.Subtle ().GenerateKey (
110
+ &Algorithm{
111
+ Name: " ECDSA" ,
112
+ Params: ecdsa.KeyGenParams {
113
+
114
+ }
115
+ }
57
116
&hmac.Algorithm {
58
117
KeyGenParams: &hmac.KeyGenParams {
59
118
Hash: " SHA-256" ,
0 commit comments