On 12/09/10, James Harper (james.har...@bendigoit.com.au) wrote:
> > I noted in my email of 14 August that I had a file with a bacula md5
> > that I was not able to match using the (Linux, Debian stable) md5 cli
> > utility.

> From memory, the MD5 is 'correct', but the base64 translation is a bit
> funny. Here's a C# version I wrote quite a while back, if it's any help.
> It's the baculaBase64 routine that's probably the most useful:

Hi James

Thanks very much for this. While trying to translate your routines into
python I came across the md5/base64 encoding routine at
http://effbot.org/librarybook/md5.htm. 

My code, which is slightly modified from the effbot original, is set out below
and works well for my purposes.

Thanks very much for posting your code.

Regards
Rory

"""
md5 sum utility with base64 encoding
adapted from http://effbot.org/librarybook/md5.htm
"""

import hashlib
import base64
import sys
import os

try:
    filename = sys.argv[1]
except IndexError:
    print "Filename required"
    sys.exit(1)

try:
    assert os.path.isfile(filename)
except AssertionError:
    print "File does not exist"
    sys.exit(1)

hash = hashlib.md5() # also possible : SHA1, SHA224, SHA256, SHA384, and SHA512 
for l in open(filename):
    hash.update(l)
value = hash.digest()

b64 = base64.encodestring(value)

# Take off the trailing '=' signs as bacula does not use them
# http://support.microsoft.com/kb/191239 suggests trailing = signs should be
# used for RFC 1521 compliance
# wierdly, a newline seems to be added to be encodedstring too, so this also
# needs to be stripped off.
print b64.strip().rstrip('=')


-- 
Rory Campbell-Lange
r...@campbell-lange.net

------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
Bacula-users mailing list
Bacula-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bacula-users

Reply via email to