jwt icon indicating copy to clipboard operation
jwt copied to clipboard

How to generate a secret?

Open weizhangxiaohan opened this issue 7 years ago • 5 comments

How to generate a secret?

Is the length of the secret fixed?

weizhangxiaohan avatar Aug 28 '19 10:08 weizhangxiaohan

Hi, What kind of algorithm you're using Symmetric or Asymmetric?

String-based secret is used in the former, here's how it works: the string converted to a byte array. The max size is Array.Length which is Int32.

However, the modern approach would be using the latter. Which doesn't use a secret, it uses a certificate instead.

abatishchev avatar Aug 28 '19 16:08 abatishchev

In the examples there is a secret key like: var secret = "GQDstcKsx0NHjPOuXOYg5MbeJ1XT0uFiwDVvVBrk";

Looks like this secret is in base64 format. Can I use Guid.NewGuid() instead?

I don't know how I can get a secret like the secret in the example.

weizhangxiaohan avatar Aug 29 '19 04:08 weizhangxiaohan

I don't think it's in bas64. I'm not sure where it's coming from, it was added in the 4th commit to this repo more than 5 years ago by prior maintainer. Maybe it's just a random string, maybe something else. It must be a random string, GUID also should work. I'm not an expert in cryptography, I would suggest additional reading. And overall I would suggest using the asymmetric algorithm with a certificate aka PKI.

abatishchev avatar Aug 29 '19 04:08 abatishchev

Thank you for your reply. It's very helpful.

weizhangxiaohan avatar Aug 29 '19 07:08 weizhangxiaohan

You're welcome!

abatishchev avatar Aug 29 '19 15:08 abatishchev