오늘도 삽질의 연속
데이터를 RSA 기반으로 암복호화 하려다 길이제한 오류가 발생하여
IllegalBlockSizeException: Data must not be longer than 256 bytes
확인해본 결과 RSA 암복호화에 길이제한이 있었다...
공개키 암호화는 역시 키교환에만 사용하고 데이터는 대칭키를 사용하여 암복호화 하도록하자
덕분에 많은것을 알고 간다... 오늘도 감사한 삽질의 하루였다...
열심히 공부하자!
RSA 암복호화 길이제한
-
RSA는 기본적으로 (Key bit수 / 8) - 11 바이트만을 암호화 복호화 할 수 있다.
-
즉, 키가 1024bit라면 (1024 / 8) - 11의 결과인 117 바이트만 암호화 복호화 가능하다.
The RSA algorithm can only encrypt data
that has a maximum byte length of the RSA key length in bits
divided with eight minus eleven padding bytes,
i.e. number of maximum bytes = key length in bits / 8 - 11.
1. generate a symmetric key
2. Encrypt the data with the symmetric key
3. Encrypt the symmetric key with rsa
4. send the encrypted key and the data
5. Decrypt the encrypted symmetric key with rsa
6. decrypt the data with the symmetric key
7. done :)
https://kwonnam.pe.kr/wiki/java/crypt/rsa
https://stackoverflow.com/questions/10007147/getting-a-illegalblocksizeexception-data-must-not-be-longer-than-256-bytes-when