Reputation: 3518
How can I sign data having a private key in javascript?
I found a really good example: example. In the example though the signature is really long. Is it possible to have it short? For example 6 characters?
Having the signature short is a bonus really. How can I do it in javascript in a first place?
Thank you!
Upvotes: 0
Views: 370
Reputation: 94038
The page you point to already shows an example in JavaScript.
You cannot have an asymmetric signature consisting of 6 characters though because that's too small to be cryptographically be secure. For 6 characters the chance of somebody simply guessing the signature would be too large.
The best you can do with existing software is probably a 64 byte ECDSA signature for a 256 bit prime curve such as P256 / secp256r1 - as standardized by NIST. There are some ways of bringing that down to 32 bytes, but that's about it.
If your problem allows for symmetric encryption then you could use a 6 byte MAC rather than a signature. Six full bytes are too short for a MAC too, but in certain situations it may be good enough.
Upvotes: 1