summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorBrad Hill <hillbrad@gmail.com>2016-04-07 15:38:00 -0700
committerJames M Snell <jasnell@gmail.com>2016-04-08 09:24:57 -0700
commit945454894bf191e3d1753647fa2d574f4692f5e3 (patch)
treefa709ffec796be3656842c9c715f0bcb4427eba2 /doc
parent7c9a691ee7d13ccf1c883e27fdb96eccc8b73d5e (diff)
downloadandroid-node-v8-945454894bf191e3d1753647fa2d574f4692f5e3.tar.gz
android-node-v8-945454894bf191e3d1753647fa2d574f4692f5e3.tar.bz2
android-node-v8-945454894bf191e3d1753647fa2d574f4692f5e3.zip
doc: add example using algorithms not directly exposed
PR-URL: https://github.com/nodejs/node/pull/6108 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
Diffstat (limited to 'doc')
-rw-r--r--doc/api/crypto.markdown22
1 files changed, 22 insertions, 0 deletions
diff --git a/doc/api/crypto.markdown b/doc/api/crypto.markdown
index 6c45d17951..6ec19ea41d 100644
--- a/doc/api/crypto.markdown
+++ b/doc/api/crypto.markdown
@@ -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