Skip to content

Instantly share code, notes, and snippets.

@hackerdem
Created May 14, 2016 16:52
Show Gist options
  • Save hackerdem/bc9f8999e87195498fdd41abcadb765c to your computer and use it in GitHub Desktop.
Save hackerdem/bc9f8999e87195498fdd41abcadb765c to your computer and use it in GitHub Desktop.
simple AES encryption and decryption
from Crypto.Cipher import AES
from Crypto import Random
def encrypt(key,message):
cipher=AES.new(key,AES.MODE_CFB,iv)
msg=cipher.encrypt(message)
print(msg)
return msg
def decrypt(key,msg):
dec=AES.new(key,AES.MODE_CFB,iv)
return dec.decrypt(msg).decode('ascii')
if __name__=='__main__':
global iv
iv=Random.new().read(AES.block_size)
key='wwwhackerdem.com'
message='You will newer walk alone'
print(decrypt(key,encrypt(key, message)))
@balasmeh
Copy link

thank you for the code , can you explain how i can encrypts the data while transfer from one database and insert into another database?
example :
select userid,pass,email from user; >>>>> database 1
{i need method to encrypts the data before insert.}
insert into user2 values(userid,pass,email)>>>> database 2

i hope you got my point , thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment