문제 상황

원인

최종 해결

최종 백엔드 복호화 코드

import javax.crypto.Cipher;
import javax.crypto.spec.OAEPParameterSpec;
import javax.crypto.spec.MGF1ParameterSpec;
import javax.crypto.spec.PSource;

@Override
public String decrypt(String encryptedData, PrivateKey privateKey) throws Exception {
  Cipher cipher = Cipher.getInstance("RSA/ECB/OAEPWithSHA-256AndMGF1Padding");
  OAEPParameterSpec oaepParams = new OAEPParameterSpec(
      "SHA-256",
      "MGF1",
      new MGF1ParameterSpec("SHA-256"),
      PSource.PSpecified.DEFAULT
  );

  cipher.init(Cipher.DECRYPT_MODE, privateKey, oaepParams);
  byte[] decryptedBytes = cipher.doFinal(Base64.getDecoder().decode(encryptedData));
  String decrypted = new String(decryptedBytes, StandardCharsets.UTF_8);
  return decrypted;
}

참고자료