当前位置: 首页>>代码示例>>Python>>正文


Python sha.sha方法代码示例

本文整理汇总了Python中sha.sha方法的典型用法代码示例。如果您正苦于以下问题:Python sha.sha方法的具体用法?Python sha.sha怎么用?Python sha.sha使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sha的用法示例。


在下文中一共展示了sha.sha方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: mangleData

# 需要导入模块: import sha [as 别名]
# 或者: from sha import sha [as 别名]
def mangleData(self, data, index):
        self.sha1_offset = 208
        self.md5_offset = 256
        self.header_offset = 360
        self.filedata_offset = 3170

        data = MangleFile.mangleData(self, data, index)

        if USE_HACHOIR:
            #data.tofile(open('/tmp/oops', 'wb'))
            hachoir_config.quiet = True
            data_str = data.tostring()
            parser = guessParser(StringInputStream(data_str))
            if parser:
                self.useHachoirParser(parser)

        summary_data = data[self.header_offset:].tostring()
        checksum = md5(summary_data).digest()
        data[self.md5_offset:self.md5_offset+16] = array('B', checksum)

        summary_data = data[self.header_offset:self.filedata_offset].tostring()
        checksum = sha(summary_data).hexdigest()
        data[self.sha1_offset:self.sha1_offset+40] = array('B', checksum)

        return data 
开发者ID:tuwid,项目名称:darkc0de-old-stuff,代码行数:27,代码来源:rpm.py

示例2: do_encrypt

# 需要导入模块: import sha [as 别名]
# 或者: from sha import sha [as 别名]
def do_encrypt(result, encrypt, salt_size=None, salt=None):
    if PASSLIB_AVAILABLE:
        try:
            crypt = getattr(passlib.hash, encrypt)
        except:
            raise ValueError("passlib does not support '%s' algorithm" % encrypt)

        if salt_size:
            result = crypt.encrypt(result, salt_size=salt_size)
        elif salt:
            result = crypt.encrypt(result, salt=salt)
        else:
            result = crypt.encrypt(result)
    else:
        raise ValueError("passlib must be installed to encrypt vars_prompt values")

    return result


# Note, sha1 is the only hash algorithm compatible with python2.4 and with
# FIPS-140 mode (as of 11-2014) 
开发者ID:soarpenguin,项目名称:python-scripts,代码行数:23,代码来源:hash_func.py

示例3: secure_hash

# 需要导入模块: import sha [as 别名]
# 或者: from sha import sha [as 别名]
def secure_hash(filename, hash_func=sha1):
    ''' Return a secure hash hex digest of local file, None if file is not present or a directory. '''

    if not os.path.exists(filename) or os.path.isdir(filename):
        return None
    digest = hash_func()
    blocksize = 64 * 1024
    try:
        infile = open(filename, 'rb')
        block = infile.read(blocksize)
        while block:
            digest.update(block)
            block = infile.read(blocksize)
        infile.close()
    except IOError as e:
        raise ValueError("error while accessing the file %s, error was: %s" % (filename, e))
    return digest.hexdigest()

# The checksum algorithm must match with the algorithm in ShellModule.checksum() method 
开发者ID:soarpenguin,项目名称:python-scripts,代码行数:21,代码来源:hash_func.py

示例4: __init__

# 需要导入模块: import sha [as 别名]
# 或者: from sha import sha [as 别名]
def __init__(self, title):
        self.title = title
        self.filename = None
        self.headcomments = ""
        self.campaign = []
        self.keywords = []
        self.crc = None
        self.sha = None
        self.preexec = None
        self.preexec_output = None 
开发者ID:medbenali,项目名称:CyberScan,代码行数:12,代码来源:UTscapy.py

示例5: dump_campaign

# 需要导入模块: import sha [as 别名]
# 或者: from sha import sha [as 别名]
def dump_campaign(test_campaign):
    print "#"*(len(test_campaign.title)+6)
    print "## %(title)s ##" % test_campaign
    print "#"*(len(test_campaign.title)+6)
    if test_campaign.sha and test_campaign.crc:
        print "CRC=[%(crc)s] SHA=[%(sha)s]" % test_campaign
    print "from file %(filename)s" % test_campaign
    print
    for ts in test_campaign:
        if ts.crc:
            print "+--[%s]%s(%s)--" % (ts.name,"-"*max(2,80-len(ts.name)-18),ts.crc)
        else:
            print "+--[%s]%s" % (ts.name,"-"*max(2,80-len(ts.name)-6))
        if ts.keywords:
            print "  kw=%s" % ",".join(ts.keywords)
        for t in ts:
            print "%(num)03i %(name)s" % t
            c = k = ""
            if t.keywords:
                k = "kw=%s" % ",".join(t.keywords)
            if t.crc:
                c = "[%(crc)s] " % t
            if c or k:
                print "    %s%s" % (c,k) 

#### COMPUTE CAMPAIGN DIGESTS #### 
开发者ID:medbenali,项目名称:CyberScan,代码行数:28,代码来源:UTscapy.py

示例6: sha1

# 需要导入模块: import sha [as 别名]
# 或者: from sha import sha [as 别名]
def sha1(x):
    return sha.sha(x).hexdigest().upper() 
开发者ID:medbenali,项目名称:CyberScan,代码行数:4,代码来源:UTscapy.py

示例7: compute_campaign_digests

# 需要导入模块: import sha [as 别名]
# 或者: from sha import sha [as 别名]
def compute_campaign_digests(test_campaign):
    dc = ""
    for ts in test_campaign:
        dts = ""
        for t in ts:
            dt = t.test.strip()
            t.crc = crc32(dt)
            dts += "\0"+dt
        ts.crc = crc32(dts)
        dc += "\0\x01"+dts
    test_campaign.crc = crc32(dc)
    test_campaign.sha = sha1(open(test_campaign.filename).read())


#### FILTER CAMPAIGN ##### 
开发者ID:medbenali,项目名称:CyberScan,代码行数:17,代码来源:UTscapy.py

示例8: archive

# 需要导入模块: import sha [as 别名]
# 或者: from sha import sha [as 别名]
def archive(self):
		import tarfile
		arch_name=self.get_arch_name()
		try:
			self.base_path
		except AttributeError:
			self.base_path=self.path
		node=self.base_path.make_node(arch_name)
		try:
			node.delete()
		except OSError:
			pass
		files=self.get_files()
		if self.algo.startswith('tar.'):
			tar=tarfile.open(arch_name,'w:'+self.algo.replace('tar.',''))
			for x in files:
				self.add_tar_file(x,tar)
			tar.close()
		elif self.algo=='zip':
			import zipfile
			zip=zipfile.ZipFile(arch_name,'w',compression=zipfile.ZIP_DEFLATED)
			for x in files:
				archive_name=self.get_base_name()+'/'+x.path_from(self.base_path)
				zip.write(x.abspath(),archive_name,zipfile.ZIP_DEFLATED)
			zip.close()
		else:
			self.fatal('Valid algo types are tar.bz2, tar.gz, tar.xz or zip')
		try:
			from hashlib import sha1 as sha
		except ImportError:
			from sha import sha
		try:
			digest=" (sha=%r)"%sha(node.read()).hexdigest()
		except Exception:
			digest=''
		Logs.info('New archive created: %s%s'%(self.arch_name,digest)) 
开发者ID:MOSAIC-UA,项目名称:802.11ah-ns3,代码行数:38,代码来源:Scripting.py

示例9: graft_path

# 需要导入模块: import sha [as 别名]
# 或者: from sha import sha [as 别名]
def graft_path(graft_points, path):
    normalized_path = os.path.realpath(path)
    for graft_point in graft_points:
        old_prefix, new_prefix = graft_point
        if normalized_path.startswith(old_prefix):
            return re.sub(r'^' + old_prefix, new_prefix, normalized_path)
    return normalized_path


# hashlib is only available in python 2.5 or higher, but the 'sha' module
# produces a DeprecationWarning in python 2.6 or higher.  We want to support
# python 2.4 and above without any stupid warnings, so let's try using hashlib
# first, and downgrade if it fails. 
开发者ID:omererdem,项目名称:honeything,代码行数:15,代码来源:helpers.py


注:本文中的sha.sha方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。