Python hashlib.algorithms() Examples
The following are 19
code examples of hashlib.algorithms().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
hashlib
, or try the search function
.
Example #1
Source File: CTConsole.py From CapTipper with GNU General Public License v3.0 | 6 votes |
def do_hashes(self,line): try: l = line.split(" ") if (l[0] == ""): self.help_hashes() else: id = int(l[0]) body, sz = CTCore.get_response_and_size(id, "all") name = CTCore.get_name(id) print " Hashes of object {} ({}):".format(str(id),name) + newLine for alg in hashlib.algorithms: hashfunc = getattr(hashlib, alg) hash = hashfunc(StringIO.StringIO(body).getvalue()).hexdigest() print " {0:8} : {1}".format(alg, hash) print "" except Exception,e: print str(e)
Example #2
Source File: models.py From openprocurement.api with Apache License 2.0 | 6 votes |
def to_native(self, value, context=None): value = super(HashType, self).to_native(value, context) if ':' not in value: raise ValidationError(self.messages['hash_invalid']) hash_type, hash_value = value.split(':', 1) if hash_type not in algorithms: raise ValidationError(self.messages['hash_invalid']) if len(hash_value) != hash_new(hash_type).digest_size * 2: raise ValidationError(self.messages['hash_length']) try: int(hash_value, 16) except ValueError: raise ConversionError(self.messages['hash_hex']) return value
Example #3
Source File: test_hashlib.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_algorithms_attribute(self): self.assertEqual(hashlib.algorithms, tuple([_algo for _algo in self.supported_hash_names if _algo.islower()]))
Example #4
Source File: test_hashlib.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_algorithms_attribute(self): self.assertEqual(hashlib.algorithms, tuple([_algo for _algo in self.supported_hash_names if _algo.islower()]))
Example #5
Source File: test_hashlib.py From BinderFilter with MIT License | 5 votes |
def test_algorithms_attribute(self): self.assertEqual(hashlib.algorithms, tuple([_algo for _algo in self.supported_hash_names if _algo.islower()]))
Example #6
Source File: bozocrack.py From EasY_HaCk with Apache License 2.0 | 5 votes |
def crack(hashstr, wordlist): for word in wordlist: for hashtype in hashlib.algorithms: func = getattr(hashlib, hashtype) if func(word).hexdigest().lower() == hashstr.lower(): return word, hashtype return None, None
Example #7
Source File: test_hashlib.py From oss-ftp with MIT License | 5 votes |
def test_algorithms_attribute(self): self.assertEqual(hashlib.algorithms, tuple([_algo for _algo in self.supported_hash_names if _algo.islower()]))
Example #8
Source File: bdbagit.py From bdbag with Apache License 2.0 | 5 votes |
def _sync_remote_entries_with_existing_fetch(self): payload_entries = self.payload_entries() for url, length, filename in self.fetch_entries(): entry_path = os.path.normpath(filename.lstrip("*")) if entry_path in payload_entries: for alg in self.algorithms: digest = payload_entries[entry_path].get(alg, None) remote_entry = self.remote_entries.get(filename) if remote_entry: continue self.add_remote_file(filename, url, length, alg, digest)
Example #9
Source File: bdbagit.py From bdbag with Apache License 2.0 | 5 votes |
def add_remote_file(self, filename, url, length, alg, digest): if alg not in self.algorithms: self.algorithms.append(alg) make_remote_file_entry(self.remote_entries, filename, url, length, alg, digest)
Example #10
Source File: bozocrack.py From recon-ng with GNU General Public License v3.0 | 5 votes |
def crack(hashstr, wordlist): for word in wordlist: for hashtype in hashlib.algorithms: func = getattr(hashlib, hashtype) if func(word).hexdigest().lower() == hashstr.lower(): return word, hashtype return None, None
Example #11
Source File: test_hashlib.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_algorithms_attribute(self): self.assertEqual(hashlib.algorithms, tuple([_algo for _algo in self.supported_hash_names if _algo.islower()]))
Example #12
Source File: test_hashlib.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_algorithms_attribute(self): self.assertEqual(hashlib.algorithms, tuple([_algo for _algo in self.supported_hash_names if _algo.islower()]))
Example #13
Source File: bdbagit.py From bdbag with Apache License 2.0 | 4 votes |
def _validate_entries(self, processes, callback=None): """ Verify that the actual file contents match the recorded hashes stored in the manifest files """ errors = list() if os.name == 'posix': worker_init = posix_multiprocessing_worker_initializer else: worker_init = None args = ((self.path, self.normalized_filesystem_names.get(rel_path, rel_path), hashes, self.algorithms) for rel_path, hashes in self.entries.items()) try: if processes == 1: count = 0 hash_results = [] totalHashes = len(self.entries.items()) for i in args: hash_results.append(_calc_hashes(i)) count += 1 if callback: if not callback(count, totalHashes): raise BaggingInterruptedError("Bag validation interrupted!") else: # pragma: no cover pool = None try: pool = multiprocessing.Pool(processes if processes else None, initializer=worker_init) hash_results = pool.map(_calc_hashes, args) finally: if pool: pool.terminate() except BaggingInterruptedError: raise # Any unhandled exceptions are probably fatal except: LOGGER.error(_("Unable to calculate file hashes for %s"), self) raise for rel_path, f_hashes, hashes in hash_results: for alg, computed_hash in f_hashes.items(): stored_hash = hashes[alg] if stored_hash.lower() != computed_hash: e = ChecksumMismatch(rel_path, alg, stored_hash.lower(), computed_hash) LOGGER.warning(force_unicode(e)) errors.append(e) if errors: raise BagValidationError(_("Bag validation failed"), errors)
Example #14
Source File: test_hashlib.py From CTFCrackTools with GNU General Public License v3.0 | 4 votes |
def __init__(self, *args, **kwargs): algorithms = set() for algorithm in self.supported_hash_names: algorithms.add(algorithm.lower()) self.constructors_to_test = {} for algorithm in algorithms: self.constructors_to_test[algorithm] = set() # For each algorithm, test the direct constructor and the use # of hashlib.new given the algorithm name. for algorithm, constructors in self.constructors_to_test.items(): constructors.add(getattr(hashlib, algorithm)) def _test_algorithm_via_hashlib_new(data=None, _alg=algorithm): if data is None: return hashlib.new(_alg) return hashlib.new(_alg, data) constructors.add(_test_algorithm_via_hashlib_new) _hashlib = self._conditional_import_module('_hashlib') if _hashlib: # These two algorithms should always be present when this module # is compiled. If not, something was compiled wrong. assert hasattr(_hashlib, 'openssl_md5') assert hasattr(_hashlib, 'openssl_sha1') for algorithm, constructors in self.constructors_to_test.items(): constructor = getattr(_hashlib, 'openssl_'+algorithm, None) if constructor: constructors.add(constructor) _md5 = self._conditional_import_module('_md5') if _md5: self.constructors_to_test['md5'].add(_md5.new) _sha = self._conditional_import_module('_sha') if _sha: self.constructors_to_test['sha1'].add(_sha.new) _sha256 = self._conditional_import_module('_sha256') if _sha256: self.constructors_to_test['sha224'].add(_sha256.sha224) self.constructors_to_test['sha256'].add(_sha256.sha256) _sha512 = self._conditional_import_module('_sha512') if _sha512: self.constructors_to_test['sha384'].add(_sha512.sha384) self.constructors_to_test['sha512'].add(_sha512.sha512) super(HashLibTestCase, self).__init__(*args, **kwargs)
Example #15
Source File: test_hashlib.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 4 votes |
def __init__(self, *args, **kwargs): algorithms = set() for algorithm in self.supported_hash_names: algorithms.add(algorithm.lower()) self.constructors_to_test = {} for algorithm in algorithms: self.constructors_to_test[algorithm] = set() # For each algorithm, test the direct constructor and the use # of hashlib.new given the algorithm name. for algorithm, constructors in self.constructors_to_test.items(): constructors.add(getattr(hashlib, algorithm)) def _test_algorithm_via_hashlib_new(data=None, _alg=algorithm): if data is None: return hashlib.new(_alg) return hashlib.new(_alg, data) constructors.add(_test_algorithm_via_hashlib_new) _hashlib = self._conditional_import_module('_hashlib') if _hashlib: # These two algorithms should always be present when this module # is compiled. If not, something was compiled wrong. assert hasattr(_hashlib, 'openssl_md5') assert hasattr(_hashlib, 'openssl_sha1') for algorithm, constructors in self.constructors_to_test.items(): constructor = getattr(_hashlib, 'openssl_'+algorithm, None) if constructor: constructors.add(constructor) _md5 = self._conditional_import_module('_md5') if _md5: self.constructors_to_test['md5'].add(_md5.new) _sha = self._conditional_import_module('_sha') if _sha: self.constructors_to_test['sha1'].add(_sha.new) _sha256 = self._conditional_import_module('_sha256') if _sha256: self.constructors_to_test['sha224'].add(_sha256.sha224) self.constructors_to_test['sha256'].add(_sha256.sha256) _sha512 = self._conditional_import_module('_sha512') if _sha512: self.constructors_to_test['sha384'].add(_sha512.sha384) self.constructors_to_test['sha512'].add(_sha512.sha512) super(HashLibTestCase, self).__init__(*args, **kwargs)
Example #16
Source File: test_hashlib.py From gcblue with BSD 3-Clause "New" or "Revised" License | 4 votes |
def __init__(self, *args, **kwargs): algorithms = set() for algorithm in self.supported_hash_names: algorithms.add(algorithm.lower()) self.constructors_to_test = {} for algorithm in algorithms: self.constructors_to_test[algorithm] = set() # For each algorithm, test the direct constructor and the use # of hashlib.new given the algorithm name. for algorithm, constructors in self.constructors_to_test.items(): constructors.add(getattr(hashlib, algorithm)) def _test_algorithm_via_hashlib_new(data=None, _alg=algorithm): if data is None: return hashlib.new(_alg) return hashlib.new(_alg, data) constructors.add(_test_algorithm_via_hashlib_new) _hashlib = self._conditional_import_module('_hashlib') if _hashlib: # These two algorithms should always be present when this module # is compiled. If not, something was compiled wrong. assert hasattr(_hashlib, 'openssl_md5') assert hasattr(_hashlib, 'openssl_sha1') for algorithm, constructors in self.constructors_to_test.items(): constructor = getattr(_hashlib, 'openssl_'+algorithm, None) if constructor: constructors.add(constructor) _md5 = self._conditional_import_module('_md5') if _md5: self.constructors_to_test['md5'].add(_md5.new) _sha = self._conditional_import_module('_sha') if _sha: self.constructors_to_test['sha1'].add(_sha.new) _sha256 = self._conditional_import_module('_sha256') if _sha256: self.constructors_to_test['sha224'].add(_sha256.sha224) self.constructors_to_test['sha256'].add(_sha256.sha256) _sha512 = self._conditional_import_module('_sha512') if _sha512: self.constructors_to_test['sha384'].add(_sha512.sha384) self.constructors_to_test['sha512'].add(_sha512.sha512) super(HashLibTestCase, self).__init__(*args, **kwargs)
Example #17
Source File: test_hashlib.py From oss-ftp with MIT License | 4 votes |
def __init__(self, *args, **kwargs): algorithms = set() for algorithm in self.supported_hash_names: algorithms.add(algorithm.lower()) self.constructors_to_test = {} for algorithm in algorithms: self.constructors_to_test[algorithm] = set() # For each algorithm, test the direct constructor and the use # of hashlib.new given the algorithm name. for algorithm, constructors in self.constructors_to_test.items(): constructors.add(getattr(hashlib, algorithm)) def _test_algorithm_via_hashlib_new(data=None, _alg=algorithm): if data is None: return hashlib.new(_alg) return hashlib.new(_alg, data) constructors.add(_test_algorithm_via_hashlib_new) _hashlib = self._conditional_import_module('_hashlib') if _hashlib: # These two algorithms should always be present when this module # is compiled. If not, something was compiled wrong. assert hasattr(_hashlib, 'openssl_md5') assert hasattr(_hashlib, 'openssl_sha1') for algorithm, constructors in self.constructors_to_test.items(): constructor = getattr(_hashlib, 'openssl_'+algorithm, None) if constructor: constructors.add(constructor) _md5 = self._conditional_import_module('_md5') if _md5: self.constructors_to_test['md5'].add(_md5.new) _sha = self._conditional_import_module('_sha') if _sha: self.constructors_to_test['sha1'].add(_sha.new) _sha256 = self._conditional_import_module('_sha256') if _sha256: self.constructors_to_test['sha224'].add(_sha256.sha224) self.constructors_to_test['sha256'].add(_sha256.sha256) _sha512 = self._conditional_import_module('_sha512') if _sha512: self.constructors_to_test['sha384'].add(_sha512.sha384) self.constructors_to_test['sha512'].add(_sha512.sha512) super(HashLibTestCase, self).__init__(*args, **kwargs)
Example #18
Source File: test_hashlib.py From BinderFilter with MIT License | 4 votes |
def __init__(self, *args, **kwargs): algorithms = set() for algorithm in self.supported_hash_names: algorithms.add(algorithm.lower()) self.constructors_to_test = {} for algorithm in algorithms: self.constructors_to_test[algorithm] = set() # For each algorithm, test the direct constructor and the use # of hashlib.new given the algorithm name. for algorithm, constructors in self.constructors_to_test.items(): constructors.add(getattr(hashlib, algorithm)) def _test_algorithm_via_hashlib_new(data=None, _alg=algorithm): if data is None: return hashlib.new(_alg) return hashlib.new(_alg, data) constructors.add(_test_algorithm_via_hashlib_new) _hashlib = self._conditional_import_module('_hashlib') if _hashlib: # These two algorithms should always be present when this module # is compiled. If not, something was compiled wrong. assert hasattr(_hashlib, 'openssl_md5') assert hasattr(_hashlib, 'openssl_sha1') for algorithm, constructors in self.constructors_to_test.items(): constructor = getattr(_hashlib, 'openssl_'+algorithm, None) if constructor: constructors.add(constructor) _md5 = self._conditional_import_module('_md5') if _md5: self.constructors_to_test['md5'].add(_md5.new) _sha = self._conditional_import_module('_sha') if _sha: self.constructors_to_test['sha1'].add(_sha.new) _sha256 = self._conditional_import_module('_sha256') if _sha256: self.constructors_to_test['sha224'].add(_sha256.sha224) self.constructors_to_test['sha256'].add(_sha256.sha256) _sha512 = self._conditional_import_module('_sha512') if _sha512: self.constructors_to_test['sha384'].add(_sha512.sha384) self.constructors_to_test['sha512'].add(_sha512.sha512) super(HashLibTestCase, self).__init__(*args, **kwargs)
Example #19
Source File: test_hashlib.py From ironpython2 with Apache License 2.0 | 4 votes |
def __init__(self, *args, **kwargs): algorithms = set() for algorithm in self.supported_hash_names: algorithms.add(algorithm.lower()) self.constructors_to_test = {} for algorithm in algorithms: self.constructors_to_test[algorithm] = set() # For each algorithm, test the direct constructor and the use # of hashlib.new given the algorithm name. for algorithm, constructors in self.constructors_to_test.items(): constructors.add(getattr(hashlib, algorithm)) def _test_algorithm_via_hashlib_new(data=None, _alg=algorithm): if data is None: return hashlib.new(_alg) return hashlib.new(_alg, data) constructors.add(_test_algorithm_via_hashlib_new) _hashlib = self._conditional_import_module('_hashlib') if _hashlib: # These two algorithms should always be present when this module # is compiled. If not, something was compiled wrong. assert hasattr(_hashlib, 'openssl_md5') assert hasattr(_hashlib, 'openssl_sha1') for algorithm, constructors in self.constructors_to_test.items(): constructor = getattr(_hashlib, 'openssl_'+algorithm, None) if constructor: constructors.add(constructor) _md5 = self._conditional_import_module('_md5') if _md5: self.constructors_to_test['md5'].add(_md5.new) _sha = self._conditional_import_module('_sha') if _sha: self.constructors_to_test['sha1'].add(_sha.new) _sha256 = self._conditional_import_module('_sha256') if _sha256: self.constructors_to_test['sha224'].add(_sha256.sha224) self.constructors_to_test['sha256'].add(_sha256.sha256) _sha512 = self._conditional_import_module('_sha512') if _sha512: self.constructors_to_test['sha384'].add(_sha512.sha384) self.constructors_to_test['sha512'].add(_sha512.sha512) super(HashLibTestCase, self).__init__(*args, **kwargs)