Input byte array has wrong 4-byte ending unit

송민지·2024년 10월 12일

개인개발

목록 보기
1/1

개인적으로 spring을 이용하여 게시판을 제작하는중에 해당 에러가 발생하였습니다.

해결과정

1. console에 출력값 확인

콘솔에 값이 정확히 오는지 확인하기 위해 sout으로 출력해보았습니다.

값이 잘 오는군요.(decode에 초록색 형광색으로 강조된 곳은 오류난곳입니다.)

구글 검색

검색결과 okky에서 힌트를 얻을 수 있었습니다.

링크된 사이트에 들어가 decode하니

공백이 보였습니다.

혹시나 싶어 다른 프로젝트에서 사용된 jwt secret key를 입력해보니 잘 되었습니다.(...)
에.. 복사를 잘못했나봅니다..

여담

호기심이 발동해 8글자를 encoding하여 프로젝트에 적용시켜보았습니다.

이번엔 43번째줄에서 오류가 발생됩니다.

The specified key byte array is 216 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. 

읽어보니 HMAC-SHA algorithms의 size가 256 bits보다 크거나 같아야 하나 봅니다.

확인해보니 9글자 까지는 해당 오류가 발생합니다. 10글자 이상 인코딩 되어야 하나 봅니다.


base64 Decode 오류

profile
항상 밝게

0개의 댓글