Skip to content

Commit

Permalink
doc: add example using algorithms not directly exposed
Browse files Browse the repository at this point in the history
PR-URL: #6108
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
  • Loading branch information
hillbrad authored and jasnell committed Apr 8, 2016
1 parent 7c9a691 commit 5665e58
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions doc/api/crypto.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,28 @@ console.log(sign.sign(private_key, 'hex'));
// Prints the calculated signature
```

A [`sign`][] instance can also be created by just passing in the digest
algorithm name, in which case OpenSSL will infer the full signature algorithm
from the type of the PEM-formatted private key, including algorithms that
do not have directly exposed name constants, e.g. 'ecdsa-with-SHA256'.

Example: signing using ECDSA with SHA256

```js
const crypto = require('crypto');
const sign = crypto.createSign('sha256');

sign.update('some data to sign');

const private_key = '-----BEGIN EC PRIVATE KEY-----\n' +
'MHcCAQEEIF+jnWY1D5kbVYDNvxxo/Y+ku2uJPDwS0r/VuPZQrjjVoAoGCCqGSM49\n' +
'AwEHoUQDQgAEurOxfSxmqIRYzJVagdZfMMSjRNNhB8i3mXyIMq704m2m52FdfKZ2\n' +
'pQhByd5eyj3lgZ7m7jbchtdgyOF8Io/1ng==\n' +
'-----END EC PRIVATE KEY-----\n',

console.log(sign.sign(private_key).toString('hex'));
```

### sign.sign(private_key[, output_format])

Calculates the signature on all the data passed through using either
Expand Down

0 comments on commit 5665e58

Please sign in to comment.