I have a column ID in oracle which was encrypted like this :
select CAST(DBMS_CRYPTO.encrypt(UTL_RAW.CAST_TO_RAW('SECRETSTRING'), 4356 , 'SOMEKEY') AS VARCHAR2(100 char)) as temp from dual;
Now i am reading this table in python using pandas. Now I want to decrypt this in python. I tried several ways, but I am unable decrypt it
Following are the things which I tried:
1)
from Cryptodome.Cipher import AES
from Cryptodome.Random import get_random_bytes
def decrypty(enc):
unpad = lambda s: s[:-ord(s[-1:])]
enc = base64.b64decode(enc)
iv = enc[:AES.block_size]
cipher = AES.new(__key__, AES.MODE_CFB, iv)
return unpad(base64.b64decode(cipher.decrypt(enc[AES.block_size:])).decode('utf8'))
this threw an error : binascii.Error: Invalid base64-encoded string: number of data characters (1) cannot be 1 more than a multiple of 4
2)
from Crypto.Cipher import AES
from Crypto import Random
def decrypt(key, enc):
enc = base64.b64decode(enc)
iv = enc[:16]
cipher = AES.new(key, AES.MODE_CBC, iv)
return unpad(cipher.decrypt(enc[16:]), block_size=16)
This threw an error related to padding.
Basically if something is encrypted in DB with a key, using the same key I am unable to decrypt it in python. any pointers ?
4356is a meaningless magic number in your code. What encryption algorithm is the equivalent for that number?dbms_crypto.encrypt_aes + dbms_crypto.pad_pkcs5 + dbms_crypto.chain_cbc.dbms_crypto.encrypt_aes + dbms_crypto.pad_pkcs5 + dbms_crypto.chain_cbc