在pycryp中使用RSA的盲因子

2024-09-30 20:28:20 发布

您现在位置:Python中文网/ 问答频道 /正文

在python中,我试图将一条消息盲化并解开它。当我解开信息的窗帘时,我不会得到原始信息。有人知道我做错了什么吗。以下是我的代码:

s = 'Hello'
loadedPublic = get_publickey()
loadedPrivate = get_privatekey()

pub = loadedPublic.blind(s,23L)
pub2 = loadedPublic.unblind(pub,23L)
return HttpResponse(pub2)

Tags: 代码信息消息hellogetblindpubprivatekey
1条回答
网友
1楼 · 发布于 2024-09-30 20:28:20

盲加密是一种使用随机元素的加密。它通常用于Blind Signatures,如下所示:

from Crypto.PublicKey import RSA
from Crypto.Hash import SHA256
from random import SystemRandom

# Signing authority (SA) key
priv = RSA.generate(3072)
pub = priv.publickey()

## Protocol: Blind signature ##

# must be guaranteed to be chosen uniformly at random
r = SystemRandom().randrange(pub.n >> 10, pub.n)
msg = "my message" * 50 # large message (larger than the modulus)

# hash message so that messages of arbitrary length can be signed
hash = SHA256.new()
hash.update(msg)
msgDigest = hash.digest()

# user computes
msg_blinded = pub.blind(msgDigest, r)

# SA computes
msg_blinded_signature = priv.sign(msg_blinded, 0)

# user computes
msg_signature = pub.unblind(msg_blinded_signature[0], r)

# Someone verifies
hash = SHA256.new()
hash.update(msg)
msgDigest = hash.digest()
print("Message is authentic: " + str(pub.verify(msgDigest, (msg_signature,))))

This是它的实现方式,因此您不能直接解开消息的隐藏,因为您没有d,因此必须首先对盲元素进行签名。为了使盲签名安全,您需要在签名模的范围内随机生成盲因子r。在

相关问题 更多 >