# How to generate secret key programmatically via auth0 jwt?

**URL:** <https://community.auth0.com/t/how-to-generate-secret-key-programmatically-via-auth0-jwt/103781>\
**Category:** Get Help\
**Tags:** configuration, application\
**Created:** [March 30, 2023, 7:55pm UTC](https://community.auth0.com/t/how-to-generate-secret-key-programmatically-via-auth0-jwt/103781 "2023-03-30T19:55:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ypkkhatri](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ypkkhatri/32/45938_2.png) [@ypkkhatri](https://community.auth0.com/u/ypkkhatri)\
**Post date:** [March 30, 2023, 7:55pm UTC](https://community.auth0.com/t/how-to-generate-secret-key-programmatically-via-auth0-jwt/103781/1 "2023-03-30T19:55:38Z")

</div>

Hello,

By using `io.jsonwebtoken` we can generate the secret key programmatically, but how can it be done in auth0 jwt?

```auto
SecretKey key = Keys.secretKeyFor(SignatureAlgorithm.HS512);
String secretString = Encoders.BASE64.encode(key.getEncoded());
System.out.println("Secret key: " + secretString);

```

Any thoughts here?

Thanks  
Yougesh

---

<div class="post-metadata">

**Author:** ![peter.fernandez](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/peter.fernandez/32/45477_2.png) [@peter.fernandez](https://community.auth0.com/u/peter.fernandez)\
**Post date:** [March 31, 2023, 10:21am UTC](https://community.auth0.com/t/how-to-generate-secret-key-programmatically-via-auth0-jwt/103781/2 "2023-03-31T10:21:55Z")

</div>

Hi Yougesh 👋

Welcome to the community 🕶

So whilst symmetric key encryption is an option, Auth0 prefers to use asymmetric key encryption when generating JWT signatures. You can read more about this [here](https://auth0.com/blog/rs256-vs-hs256-whats-the-difference/). Asymmetric key encryption is much more manageable and reduces security risk as the private key is _only_ ever generated, held and managed by Auth0.

Hope this helps 🙂

---

<div class="post-metadata">

**Author:** ![ypkkhatri](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ypkkhatri/32/45938_2.png) [@ypkkhatri](https://community.auth0.com/u/ypkkhatri)\
**Post date:** [March 31, 2023, 10:57pm UTC](https://community.auth0.com/t/how-to-generate-secret-key-programmatically-via-auth0-jwt/103781/3 "2023-03-31T22:57:15Z")

</div>

@peter.fernandez Thanks for the answer, that helps.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [April 14, 2023, 10:58pm UTC](https://community.auth0.com/t/how-to-generate-secret-key-programmatically-via-auth0-jwt/103781/4 "2023-04-14T22:58:03Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
