# WeakKeyException when trying to retreive JWT Token

**URL:** <https://devforum.zoom.us/t/weakkeyexception-when-trying-to-retreive-jwt-token/24453>\
**Category:** API and Webhooks\
**Created:** [July 17, 2020, 6:03pm UTC](https://devforum.zoom.us/t/weakkeyexception-when-trying-to-retreive-jwt-token/24453 "2020-07-17T18:03:28Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ajay.prabhakaran](https://avatars.discourse-cdn.com/v4/letter/a/d07c76/32.png) [@ajay.prabhakaran](https://devforum.zoom.us/u/ajay.prabhakaran)\
**Post date:** [July 17, 2020, 6:03pm UTC](https://devforum.zoom.us/t/weakkeyexception-when-trying-to-retreive-jwt-token/24453/1 "2020-07-17T18:03:28Z")

</div>

**Description**  
I am trying to write Java code (to be run on the server side) to get the JWT token programatically. I have a JWT App with API Key and secret from the same. When running the code, I get an exception

**Error**  
The full error message or issue you are running into.  
Exception in thread “main” io.jsonwebtoken.security.WeakKeyException: The specified key byte array is 80 bits which is not secure enough for any JWT HMAC-SHA algorithm. The JWT JWA Specification (RFC 7518, Section 3.2) states that keys used with HMAC-SHA algorithms MUST have a size \>= 256 bits (the key size must be greater than or equal to the hash output size). Consider using the io.jsonwebtoken.security.Keys#secretKeyFor(SignatureAlgorithm) method to create a key guaranteed to be secure enough for your preferred HMAC-SHA algorithm. See [https://tools.ietf.org/html/rfc7518#section-3.2](https://tools.ietf.org/html/rfc7518#section-3.2) for more information.  
at io.jsonwebtoken.security.Keys.hmacShaKeyFor(Keys.java:96)

**Which App Type (OAuth / Chatbot / JWT / Webhook)?**  
JWT

**Which Endpoint/s?**  
Not yet got there

**How To Reproduce (If applicable)**  
private\*\* **void** createJWTToken() {  
Map\<String, Object\> header = **new** HashMap\<\>();  
header.put(“alg”, “HS256”);  
header.put(“type”, “JWT”);  
SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm. _ **HS256** _ ;  
SecretKey key = Keys. _hmacShaKeyFor_ (“SECRET\_KEY”.getBytes(StandardCharsets. _ **UTF\_8** _ ));  
String jwt = **null** ;  
jwt = Jwts. _builder_ ()  
.setHeader(header)  
.setIssuer( _ **API\_KEY** _ )  
.setExpiration( **new** Date( **new** Date().getTime()+80000000))  
.signWith(key, signatureAlgorithm).compact();  
System. _ **out** _ .println(jwt);  
}

**Screenshots (If applicable)**  
If applicable, add screenshots to help explain your problem.

**Additional context**  
Add any other context about the problem here.

---

<div class="post-metadata">

**Author:** ![ajay.prabhakaran](https://avatars.discourse-cdn.com/v4/letter/a/d07c76/32.png) [@ajay.prabhakaran](https://devforum.zoom.us/u/ajay.prabhakaran)\
**Post date:** [July 20, 2020, 7:34am UTC](https://devforum.zoom.us/t/weakkeyexception-when-trying-to-retreive-jwt-token/24453/2 "2020-07-20T07:34:52Z")

</div>

Modified code to  
@SuppressWarnings(“deprecation”)

**private**  **void** createJWTToken() {

SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm. _ **HS256** _ ;

//SecretKey key = Keys.hmacShaKeyFor(SECRET\_KEY.getBytes(StandardCharsets.UTF\_8));

String jwt = **null** ;

**try** {

jwt = Jwts. _builder_ ()

.setHeaderParam(“typ”, “JWT”)

.setIssuer( _ **API\_KEY** _ )

.setExpiration( **new** Date( **new** Date().getTime()+80000000))

//.signWith(key, signatureAlgorithm)

.signWith(signatureAlgorithm, _ **SECRET\_KEY** _ .getBytes(“UTF-8”))

.compact();

} **catch** (InvalidKeyException | UnsupportedEncodingException e) {

e.printStackTrace();

}

System. _ **out** _ .println(jwt);

}

and now getting  
Exception in thread “main” java.lang.AbstractMethodError: io.jsonwebtoken.impl.DefaultJwtBuilder.signWith(Ljava/security/Key;Lio/jsonwebtoken/SignatureAlgorithm;)Lio/jsonwebtoken/JwtBuilder;

---

<div class="post-metadata">

**Author:** ![ajay.prabhakaran](https://avatars.discourse-cdn.com/v4/letter/a/d07c76/32.png) [@ajay.prabhakaran](https://devforum.zoom.us/u/ajay.prabhakaran)\
**Post date:** [July 20, 2020, 2:42pm UTC](https://devforum.zoom.us/t/weakkeyexception-when-trying-to-retreive-jwt-token/24453/3 "2020-07-20T14:42:35Z")

</div>

Used oracle.security.restsec.jwt.JwtToken and it works fine.

---

<div class="post-metadata">

**Author:** ![tommy](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/tommy/32/72769_2.png) [@tommy](https://devforum.zoom.us/u/tommy)\
**Post date:** [July 22, 2020, 10:43pm UTC](https://devforum.zoom.us/t/weakkeyexception-when-trying-to-retreive-jwt-token/24453/4 "2020-07-22T22:43:52Z")

</div>

Happy to hear you got it working @ajay.prabhakaran! 🙂

Thanks,  
Tommy

---

<div class="post-metadata">

**Author:** ![larryhems](https://avatars.discourse-cdn.com/v4/letter/l/7bcc69/32.png) [@larryhems](https://devforum.zoom.us/u/larryhems)\
**Post date:** [October 14, 2020, 6:54am UTC](https://devforum.zoom.us/t/weakkeyexception-when-trying-to-retreive-jwt-token/24453/5 "2020-10-14T06:54:40Z")

</div>

> [@ajay.prabhakaran](#):
>
> Exception in thread “main” java.lang.AbstractMethodError:

This error is thrown when an application tries to call an abstract method without actual implementation. Abstract methods have no body and cannot be executed. This error can only occur at run time if the definition of some class has incompatibly changed since the currently executing method was last compiled. It usually happens after some library is upgraded while some is not. The dependencies are missing somehow. This means that you are using an old [java](http://net-informations.com/java/default.htm) version of an interface implementation which is missing a new interface method. For example java.sql.Connection interface got a new getSchema method in 1.7. If you have 1.6 JDBC driver and call Connection.getSchema you will get AbstractMethodError. So, make sure you have the latest jar file in your class path not a older copy.

---

<div class="post-metadata">

**Author:** ![will.zoom](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/will.zoom/32/14417_2.png) [@will.zoom](https://devforum.zoom.us/u/will.zoom)\
**Post date:** [October 15, 2020, 6:01pm UTC](https://devforum.zoom.us/t/weakkeyexception-when-trying-to-retreive-jwt-token/24453/6 "2020-10-15T18:01:14Z")

</div>

Thanks for jumping in with this context, @larryhems! 💯

Best,  
Will
