実際、公開鍵で暗号化されたメッセージを復号化するには、秘密指数があれば十分です。
これは、メッセージに署名できることも意味します。署名は基本的に、秘密鍵を使用して平文を*復号化*するだけであり、公開鍵を使用して*暗号化*すると、平文が再び提供されるためです。通常、前に平文でハッシュダイジェストを使用し、それに署名します...
n
のみをd
使用してメッセージを復号化できない理由はpyrcypto
、メッセージの復号化中にブラインドステップを実行するためです。これには、公開指数が含まれますが、復号化には実際には必要ありません。
ただし、プライベートAPIへの呼び出しを使用することで、この手順をバイパスできます。
したがって、これは機能するはずです。
from Crypto.PublicKey import RSA
from Crypto.Util.number import bytes_to_long, long_to_bytes
full = RSA.generate(2048)
# construct key using only n and d
try:
# pycrypto >=2.5, only tested with _slowmath
impl = RSA.RSAImplementation(use_fast_math=False)
partial = impl.construct((full.n, 0L))
partial.key.d = full.d
except TypeError:
# pycrypto <=2.4.1
partial = RSA.construct((full.n, 0L, full.d))
pub = full.publickey()
# create message with padding
# http://en.wikipedia.org/wiki/RSA_%28algorithm%29#Padding_schemes
cleartext = ...
signature = partial.sign(cleartext, None)
print "validating message: ", pub.verify(cleartext, signature)
message = pub.encrypt(cleartext, None)
# bypassing the blinding step on decrypt
enc_msg=map(bytes_to_long, message)
dec_msg = map(partial.key._decrypt, enc_msg)
print "decrypting: "
for m in dec_msg:
print long_to_bytes(m)