

String res = new String(cipher.doFinal(Base64.getMimeDecoder().decode(str)), "utf-8") Įxception in Java .util.BadBlockException: unable to decrypt blockĬaused by:. Java PublicKey pubKey = CertificateFactory.getInstance("X.509").generateCertificate(new ByteArrayInputStream(decodeBase64(PUBLIC_KEY))).getPublicKey() Ĭipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding", new Bounc圜astleProvider()) Ĭipher.init(Cipher.DECRYPT_MODE, pubKey) Sometimes my decrypted number (message) does not match my original number (the message I needed to encrypt and decrypt). KEY = "-BEGIN RSA PRIVATE KEY-\n" \Įnc_text = rsa_cipher.encrypt("Hello Stackoverflow".encode('utf-8'))Įnc_text_64 = base64.b64encode(cipher_text).decode("utf-8") So I am trying to create a very simple RSA encryption/decryption program where I only encrypt/decrypt int numbers. encrypt in Java or Python with public key and decrypt with private and vice versa encrypt in Java or Python with private key and decrypt with public) I tried multiple combinations with PKCS1_OAEP and hash algorythms but getting the same error.Īt the same time encription / decription within the same platform works fine (e.g. Below is Python/Java source codes and exception. I make RSA encryption in python with private key and cannot decrypt in Java with public key.
