일자 : 24.04.15
작성자 : 김민수
로그인 기능을 구현하고 PostMan에서 로그인 요청을 테스트하던 도중에 생긴 오류이다.
<aside> 💡 오류 내용
io.jsonwebtoken.security.WeakKeyException: The signing key's size is 440 bits which is not secure enough for the HS512 algorithm. The JWT JWA Specification (RFC 7518, Section 3.2) states that keys used with HS512 MUST have a size >= 512 bits (the key size must be greater than or equal to the hash output size). Consider using the io.jsonwebtoken.security.Keys class's 'secretKeyFor(SignatureAlgorithm.HS512)' method to create a key guaranteed to be secure enough for HS512. See https://tools.ietf.org/html/rfc7518#section-3.2 for more information.
</aside>
이전 프로젝트에서 사용했던 로직을 사용하였기에 큰 문제가 없을 것이라 판단을 하였지만 실제로 해당 오류가 발생하였기에 내용을 정리하게 되었다.
오류 내용을 천천히 읽어보자.
오류 내용을 읽어보니 해결 방법도 같이 제공을 하고 있었기에 이를 바탕으로 기존에 사용했던 secretKey를 재수정하기로 하였다.
이때 해당 bits를 고려해가면서 직접 키를 다시 만들기는 번거롭다고 판단하였고 이를 위해 다른 방법을 사용하기로 했다. 먼저 기존의 코드는 다음과 같다. Application.yml에서 지정한 jwt.secret.key를 가져와서 사용하는 방식이었다.