Пример #1
0
 def verify(self, signature, msg, key):
     """ check if the signature is correct according to the public key path given
         and the message """
     msg = self.remove_sign(msg)
     key = RSA.importKey(key)
     ha = SHA.SHA1Hash().new(msg)
     verifier = PKCS1_v1_5.new(key)
     signature = urllib.unquote(signature)
     signature = base64.b64decode(signature)
     return verifier.verify(ha, signature)
Пример #2
0
def pow(conn):
    res = conn.recv_fixed_size(12)
    i = random.randint(0, 2**32 - 1)
    i = 2131672237762560000
    while True:
        i += 1
        i %= 2**32
        x = res + ('%08x' % i).encode()
        if i % 10000 == 0:
            print(i)

        tmp = SHA.SHA1Hash(x).digest()

        if tmp.endswith(b'\x00\x00\x00'):
            print(tmp, x)
            print('found it')
            conn.send(x)
            break
    pass
Пример #3
0
 def sign(self, message, skey):
     m = SHA.SHA1Hash(message).digest()
     s, = skey.sign(m, 0)
     sig = number.long_to_bytes(s)
     return sig
Пример #4
0
 def verify(self, message, sig, pkey):
     m = SHA.SHA1Hash(message).digest()
     return pkey.verify(m, sig)
Пример #5
0
    },
    "sha256": {
        "hashlib_hash": hashlib.new("sha256"),
        "crypto_hash": SHA256.SHA256Hash()
    },
    "sha384": {
        "hashlib_hash": hashlib.new("sha384"),
        "crypto_hash": SHA384.SHA384Hash()
    },
    "sha512": {
        "hashlib_hash": hashlib.new("sha512"),
        "crypto_hash": SHA512.SHA512Hash()
    },
    "sha1": {
        "hashlib_hash": hashlib.new("sha1"),
        "crypto_hash": SHA.SHA1Hash()
    },
    "ripemd160": {
        "hashlib_hash": hashlib.new("ripemd160"),
        "crypto_hash": RIPEMD.RIPEMD160Hash()
    }
}


# takes hasher
def hashFile(filename, hasher):
    return hashit.hashIter(hashit.blockIter(open(filename, "rb")), hasher)


def hashStr(binary, hasher):
    hasher.update(binary)