encrypt icon indicating copy to clipboard operation
encrypt copied to clipboard

How to decrypt a string encrypted with Python.

Open JacoFourie opened this issue 3 years ago • 2 comments

Hi.

Sorry to bug you. I need to decrypt some data that is encrypted in Python using Blowfish.

Here is the Python code that will create a encrypted base64 string. I need the Dart code to decrypt it. Can somebody please help me with it?

`#!/usr/bin/python from Crypto.Cipher import Blowfish import base64

blocksize = Blowfish.block_size keystr = b'this is my key' iv = b'abcdefgh'

cipher = Blowfish.new(keystr, Blowfish.MODE_CBC, iv)

data_string = 'This is my data'

while len(data_string) % blocksize !=0: data_string = data_string + ' '
encrypted_data = cipher.encrypt(data_string) encoded = base64.b64encode(encrypted_data)

print(b'Encrypted Base64 String : ' + encoded)`

This is the output.

Encrypted Base64 String : gxZXDnt1ek/Ivx91kjwJXg==

So I need to take the string

gxZXDnt1ek/Ivx91kjwJXg==

back to

This is my data

JacoFourie avatar Aug 17 '21 16:08 JacoFourie

Here is the Python code to use AES and not Blowfish.

#!/usr/bin/python from Crypto.Cipher import AES import base64

blocksize = 16 keystr = b'mysimplekey ' iv = b'123456 ' data_string = 'This is my data'

#pad with spaces until 16 bytes while len(data_string) % blocksize !=0: data_string = data_string + ' '

cipher = AES.new(keystr, AES.MODE_CBC, iv)

encrypted_data = cipher.encrypt(data_string) encoded = base64.b64encode(encrypted_data)

print(b'Encrypted Base64 String : ' + encoded) The output is

Encrypted Base64 String : zd3qRzdrFGsoxjJ2iJbTyw==

So what will the code be in dart to use AES to get the text

zd3qRzdrFGsoxjJ2iJbTyw==

back to

This is my data

JacoFourie avatar Aug 18 '21 10:08 JacoFourie

JacoFourie any update or did you find any solution?

vistaar-mlopes avatar Apr 10 '24 06:04 vistaar-mlopes