Why we are unable to decrypt the data in java that is encrypted in python using RSA Encryption using ECB/PKCS1 -


here code encrypting data in python

from crypto.cipher import aes crypto.publickey import rsa crypto.hash import sha256 base64 import b64decode import base64   mode = aes.mode_cbc key_bytes="htj9baaamg9xxk6uls4jgg==" # random 128 bit key generated  iv_bytes = "secretkey" cipher = aes.new(key_bytes, mode, iv_bytes)   def pad(text): bytenum = len(text) packinglength = 8 - bytenum % 8 appendage = chr(packinglength) * packinglength data=text + appendage return data   plain_text="some text encrypt" data = pad(plain_text) encrypted_bytes = cipher.encrypt(data) encrypted_string = base64.urlsafe_b64encode(encrypted_bytes) encrytid = open("encryptid.txt",'w')      #writting encrypted data ref encrytid.write(encrypted_string) encrytid.close() keys = b64decode('htj9baaamg9xxk6uls4jgg==') key = (open('public.pem', 'rb').read())   #reading public.pem data rsakey = rsa.importkey(key) rsakey = pkcs1_oaep.new(rsakey) encrypted = rsakey.encrypt(keys)                         #print ("enc: ", encrypted) encrypt_aes = base64.b64encode(encrypted) 

and here java code use decrypt above output:

when try decrypt data using java getting bellow error:

error

javax.crypto.badpaddingexception: decryption error  @ sun.security.rsa.rsapadding.unpadv15(unknown source)  @ sun.security.rsa.rsapadding.unpad(unknown source)  @ com.sun.crypto.provider.rsacipher.dofinal(rsacipher.java:363)  @ com.sun.crypto.provider.rsacipher.enginedofinal(rsacipher.java:389)  @ javax.crypto.cipher.dofinal(cipher.java:2121) 

can 1 suggest possible solution resolve issue...

you using oaep encryption in python , pkcs#1 padding decryption in java. 2 different rsa encryption schemes, if both present in pkcs#1 v2.1 , 2.2 standards. should use oaep (using sha-1 default) in java well. should present oracle jre.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -