hier ein kurzes Beispiel, wie man mit PyCrypto mit einem Passwort, das man übergibt, einen Text verschlüsselt und dann wieder entschlüsselt. Es benötigt
http://www.amk.ca/files/python/crypto/p ... 0.1.tar.gz
und
http://sourceforge.net/projects/yawpycrypto
(Mein kleines Skript soll die dortigen Beispielskripte noch etwas mehr verdeutlichen):
Code: Alles auswählen
#!/usr/bin/env python
import os
import sys
import base64
from yawPyCrypto.Cipher import DecryptCipher, EncryptCipher
from yawPyCrypto.Cipher import ZipDecryptCipher, ZipEncryptCipher
from yawPyCrypto.Constants import CIPHER_BLOWFISH, MODE_CBC
def doEncrypt(text, passw = None):
e = EncryptCipher(passw, CIPHER_BLOWFISH, MODE_CBC)
e.feed(text)
e.finish()
encryptedtext = e.data
if passw != None:
passwr = passw
else:
passwr = e.password
a = (encryptedtext, passwr)
return a
def doDecrypt(encryptedtext, passw):
d = DecryptCipher(passw)
d.feed(encryptedtext)
d.finish()
decoded = (d.data)
return decoded
# Calling the encryption routine.
# If you just pass the text to encrypt, a password is generated:
a = doEncrypt("For your eyes only !", "Melina")
# Just trying to clean the screen:
if sys.platform == "win32":
os.system("cls")
else:
os.system("clear")
print
print "Hello !"
print
print "I just encrypted some text. It looks like this now:"
print
print base64.b64encode(a[0])
print
print 'Please notice, that I just encoded the text once more using "base64.b64encode()" to make it printable.'
print
print "The password for decryption is: "
print
print base64.b64encode(a[1])
print
print "Let's decrypt again (the original password must be passed without b64encoding):"
print
print doDecrypt(a[0], a[1])
print