base64 encoding is in no way encryption - no 'key' is required in
order to reverse it. This may or may not be an issue for you, but
basically base64 is equivalent to no encryption.
sha or equivalent "hashing" is one-way, so no, it cannot be reversed.
AES and similar algorithms are "proper" encryption, but the data
requires some preparation:
def addPadding(s, mod):
""" Adds padding sufficient to match mod blocksize """
offset = struct.calcsize("L")
packedSize = struct.pack("L", len(s))
paddingSize = mod - (len(s)+offset) % mod
return packedSize+s+('\x00' * paddingSize)
def stripPadding(padded):
""" Removes the padding from the string """ sizeLen =
struct.calcsize("L")
(size,) = struct.unpack("L", padded[:sizeLen])
return padded[sizeLen:size+sizeLen]
Will give you the basic results you're after, addPadding("my string",
32) will return a structured piece of data with null padding on the
end, suitable for encryption using a 32-byte block cipher. On
decryption, you should use stripPadding() to give you back the
original string.
to encrypt:
co = AES.new(cryptoKey, AES.MODE_CBC, iv)
ciphertext = co.encrypt(addPadding(plaintext, 32))
to decrypt:
co = AES.new(cryptoKey, AES.MODE_CBC, iv)
plaintext = stripPadding(co.decrypt(ciphertext))
Please note that the output of .encrypt is a 'binary' string, that is,
it won't necessarily work in database fields (depends on the type)
etc. You may need to base64 encode the result of the encrypt function
to ensure it will store correctly.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---