标签: hashlib

没有模块_sha256安装cellProfiler

我正在尝试在linux上为开发人员安装cellprofiler,并获得一个名为"_sha256"的"无模块"错误.我在几个博客上找到了解决方案,但没有任何效果,有人可以帮我解决这个问题吗?

这是我的配置:

Python 2.7.3 (default, Aug  1 2012, 05:16:07) 
[GCC 4.6.3] on linux2
Run Code Online (Sandbox Code Playgroud)

linux:

uname -m
i686

Distributor ID: Ubuntu
Description:    Ubuntu 12.04.2 LTS
Release:        12.04
Codename:       precise
Run Code Online (Sandbox Code Playgroud)

这是我得到的错误:

local@pc-ellenberg23:~/Softwares/cellProfiler/CellProfiler$ make -f Makefile.CP2 PREFIX="${HOME}/usr/cp2"
All pre-checks executed successfully.
export PATH="/home/local/usr/cp2/bin:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/lib/jvm/java-7-openjdk-i386/bin:/usr/lib/jvm/java-7-openjdk-i386/bin:/usr/lib/jvm/java-7-openjdk-i386/bin" && \
                    export LD_LIBRARY_PATH="/home/local/usr/cp2/lib:${LD_LIBRARY_PATH}" && \
                    sh setuptools-0.6c11-py2.6.egg --prefix="/home/local/usr/cp2"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/local/Softwares/cellProfiler/CellProfiler/setuptools-0.6c11-py2.6.egg/setuptools/command/easy_install.py", line 21, in <module>
  File "/home/local/Softwares/cellProfiler/CellProfiler/setuptools-0.6c11-py2.6.egg/setuptools/package_index.py", line 2, in <module>
  File "/home/local/usr/cp2/lib/python2.6/urllib2.py", line 93, in <module>
    import hashlib …
Run Code Online (Sandbox Code Playgroud)

python sha256 hashlib

2
推荐指数
1
解决办法
3066
查看次数

通过hashlib查找重复文件?

我知道之前已经问过这个问题,我已经看到了一些答案,但这个问题更多的是关于我的代码和完成这项任务的最佳方法.

我想扫描一个目录,看看该目录中是否有任何重复项(通过检查MD5哈希).以下是我的代码:

import sys
import os
import hashlib

fileSliceLimitation = 5000000 #bytes

# if the file is big, slice trick to avoid to load the whole file into RAM
def getFileHashMD5(filename):
     retval = 0;
     filesize = os.path.getsize(filename)

     if filesize > fileSliceLimitation:
        with open(filename, 'rb') as fh:
          m = hashlib.md5()
          while True:
            data = fh.read(8192)
            if not data:
                break
            m.update(data)
          retval = m.hexdigest()

     else:
        retval = hashlib.md5(open(filename, 'rb').read()).hexdigest()

     return retval

searchdirpath = raw_input("Type directory you wish to search: ")
print "" …
Run Code Online (Sandbox Code Playgroud)

python file duplicates hashlib

2
推荐指数
1
解决办法
2288
查看次数

Unix md5与python的hashlib.md5不同吗?

echo lol | md5在Mac终端上运行它返回: 59bcc3ad6775562f845953cf01624225

但后来我print hashlib.md5("lol").hexdigest()在python 2.7中运行,我得到: 9cdfb439c7876e703e307864c9167a15

我究竟做错了什么?

python unix hash md5 hashlib

2
推荐指数
1
解决办法
778
查看次数

Python hashlib没有为md5生成正确的哈希

我正在研究一个小的python程序,它将使用word文件强制执行md5哈希.程序将获取您的哈希值,然后您可以选择要用作单词列表的文件.然后它将在文件中逐行进行并生成md5哈希版本以检查您输入的版本.如果它们匹配,那么它将告诉你产生该哈希的单词.问题是,当程序将行转换为哈希值时,它不会产生正确的可识别md5哈希值.例如,它说测试的md5哈希是d8e8fca2dc0f896fd7cb4cb0031ba249.我已经尝试了多种编码文本和诸如此类的方法,但找不到正确的答案.我究竟做错了什么?

import hashlib

mainhash = raw_input("What hash would you like to try and break?")
filename = raw_input("What file would you like to use?")
times = 0


if filename == "":
    print "A list file is required."
    exit()

f = open(filename)
for line in iter(f):
    times = times + 1
    word = line
    line = hashlib.md5(line.encode("utf")).hexdigest()
    print line
    if line == mainhash:
        print "Matching Hash found. Word is:"
        print word
        print times
        exit()

f.close()
print "Sorry no match was found. Please …
Run Code Online (Sandbox Code Playgroud)

python hash md5 hashlib

2
推荐指数
1
解决办法
983
查看次数

OS X上的Python 2.7:TypeError:'frozenset'对象在每个命令上都不可调用

我在Python的每个命令上都有这个错误:

?  /tmp sudo easy_install pip
Traceback (most recent call last):
  File "/usr/bin/easy_install-2.7", line 11, in 
    load_entry_point('setuptools==1.1.6', 'console_scripts', 'easy_install')()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 357, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 2394, in load_entry_point
    return ep.load()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 2108, in load
    entry = __import__(self.module_name, globals(),globals(), ['__name__'])
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/__init__.py", line 11, in 
    from setuptools.extension import Extension
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/extension.py", line 5, in 
    from setuptools.dist import _get_unpatched
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/dist.py", line 15, in 
    from setuptools.compat import numeric_types, basestring
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/compat.py", line 17, in …

python hashlib python-2.7 frozenset

2
推荐指数
1
解决办法
7205
查看次数

使用hashlib.sha256创建唯一的id; 这保证是独一无二的吗?

我正在尝试使用以下函数创建唯一的记录ID:

import hashlib
from base64 import b64encode

def make_uid(salt, pepper, key):
  s = b64encode(salt)
  p = b64encode(pepper)
  k = b64encode(key)
  return hashlib.sha256(s + p + k).hexdigest()
Run Code Online (Sandbox Code Playgroud)

在哪里pepper设置如下:

uuid_pepper = uuid.uuid4()
pepper = str(uuid_pepper).encode('ascii')
Run Code Online (Sandbox Code Playgroud)

saltkey是为每个请求的值相同.

我的问题是,由于辣椒的独特性,make_uid这种情况总会返回一个独特的价值,或者它是否有可能产生重复?

建议的答案是不同的,因为我不要求有关各种UUID类型的独特性,我想知道它是否在所有可能的SHA256哈希创建两个不同的输入之间的冲突.

python uuid hashlib

2
推荐指数
1
解决办法
1807
查看次数

hashlib 中`block_size` 和`digest_size` 的区别?

我正在浏览 Pythonhashlib包文档,并希望对两个哈希对象属性(即hash.block_sizehash.digest_size)进行澄清。下面是每个属性的定义:

hash.digest_size= "结果散列的大小,以字节为单位。"
hash.block_size= "哈希算法的内部块大小,以字节为单位。"
来源:https : //docs.python.org/2/library/hashlib.html

所以我理解这hash.digest_size只是数据被 hash_object 散列或“消化”后的长度或大小(以字节为单位)。例如,从下面的代码中,通过 SHA256 哈希对象获取字符串“Hello World”的摘要会返回 32 字节(或 256 位)的digest_size。

import hashlib
hash_object = hashlib.sha256()
hash_object.update(b'Hello World')
hex_dig = hash_object.hexdigest()

print(hex_dig)
>>>a591a6d40bf420404a011733cfb7b190d62c65bf0bcda32b57b277d9ad9f146e
print(hash_object.digest_size)
>>>32
print(hash_object.block_size)
>>>64 
print(len(hex_dig))
>>>64
Run Code Online (Sandbox Code Playgroud)

我不明白的是这个hash.block_size属性。是否只是表示散列数据的十六进制表示所需的字符长度?完全是别的东西吗?我不太明白这个属性的定义,所以对此的任何澄清都会非常有帮助和有见地!

python hashlib python-3.x

2
推荐指数
1
解决办法
2920
查看次数

如何在 C# 中获得 sha3-512 哈希?

的exaple,字符串“测试”在https://md5calc.com/hash/sha3-512/test给我“9ece086e9bac491fac5c1d1046ca11d737b92a2b2ebd93f005d7b710110c0a678288166e7fbe796883a4f2e9b3ca9f484f521d0ce464345cc1aec96779149c14”

using HashLib; // from https://www.nuget.org/packages/HashLib
using System;

class Program
{
    static void Main(string[] args)
    {
        var sha3512 = HashFactory.Crypto.SHA3.CreateKeccak512();
        var tempHash = sha3512.ComputeString("test");
        Console.WriteLine(tempHash.ToString().ToLower().Replace("-", ""));
    }
}
Run Code Online (Sandbox Code Playgroud)

返回“3abff7b1f2042ac3861bd4c0b40efaa8a695909bfb31753fc7b1bd69778de1225a627c8f07cf4814cc05435ada2a7ff​​ee3f451158484b74b7524b7524525252545254525253fc7fc7b1bd69778de1225a627c8f07cf2042f2042525257525253fc7b1bd69778de1225a627c8f07cf2042525252753fc7b1bd69778de1225a627c8f07cf4545252752527525254525456

我需要获取第一个字符串,而不是 hashlib 提供的字符串。

c# hash sha sha-3 hashlib

2
推荐指数
1
解决办法
6726
查看次数

Python 3.9.8、hashlib 和 RIPEMD160

运行 MacOS 10.14.6。刚刚运行 MacPorts 更新。采用 Python 3.9.7 -> 3.9.8 和 OpenSSL 1.1.3 -> 3。

运行现有的 Python 代码表明有些东西出问题了hashlib,RIPEMD160 不再可用(Whirlpool 也可能还有其他摘要)。

Traceback (most recent call last):
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/hashlib.py", line 160, in __hash_new
    return _hashlib.new(name, data, **kwargs)
ValueError: [digital envelope routines] initialization error

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "testhash.py", line 3, in <module>
    r160 = hashlib.new('ripemd160')
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/hashlib.py", line 166, in __hash_new
    return __get_builtin_constructor(name)(data)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/hashlib.py", line 123, in __get_builtin_constructor
    raise …
Run Code Online (Sandbox Code Playgroud)

openssl macports hashlib python-3.x

2
推荐指数
1
解决办法
3498
查看次数

Python相当于java PBKDF2WithHmacSHA1

我的任务是构建一个API的使用者,该API需要一个加密的令牌,其种子值是UNIX时间.我展示的示例是使用我不熟悉的Java实现的,在阅读完文档和其他堆栈文章之后,我们无法找到解决方案.

使用javax.crypto.SecretKey,javax.crypto.SecretKeyFactory,javax.crypto.spec.PBEKeySpec,和javax.crypto.spec.SecretKeySpec协议,我需要生成令牌类似如下:

public class EncryptionTokenDemo {

    public static void main(String args[]) {
        long millis = System.currentTimeMillis();
        String time = String.valueOf(millis);
        String secretKey = "somekeyvalue";
        int iterations = 12345;
        String iters = String.valueOf(iterations);
        String strToEncrypt_acctnum = "somevalue|" + time + "|" + iterations;

        try {

            byte[] input = strToEncrypt_acctnum.toString().getBytes("utf-8");
            byte[] salt = secretKey.getBytes("utf-8");
            SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
            SecretKey tmp = factory.generateSecret(new PBEKeySpec(secretKey.toCharArray(), salt, iterations, 256));
            SecretKeySpec skc = new SecretKeySpec(tmp.getEncoded(), "AES");
            Cipher cipher …
Run Code Online (Sandbox Code Playgroud)

python java hashlib pbkdf2 hmacsha1

1
推荐指数
1
解决办法
1048
查看次数

标签 统计

hashlib ×10

python ×8

hash ×3

md5 ×2

python-3.x ×2

c# ×1

duplicates ×1

file ×1

frozenset ×1

hmacsha1 ×1

java ×1

macports ×1

openssl ×1

pbkdf2 ×1

python-2.7 ×1

sha ×1

sha-3 ×1

sha256 ×1

unix ×1

uuid ×1