我在 pysodium 0.6.6 中使用带有 python 绑定的 libsodium
使用crypto_box
and时crypto_box_open
,我总是得到一个ValueError
. 这是一个简单的例子:
import pysodium
import random
serverPK, serverSK = pysodium.crypto_box_keypair()
clientPK, clientSK = pysodium.crypto_box_keypair()
testText = "test message"
nonce1 = str(random.random())
nonce2 = str(random.random())
cipherText = pysodium.crypto_secretbox(testText,nonce1,clientPK)
message = pysodium.crypto_secretbox_open(cipherText, nonce2, clientSK)
print message
这是错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/.../pysodium-0.6.6/pysodium/__init__.py", line 181, in crypto_box_open
__check(sodium.crypto_box_open(msg, padded, ctypes.c_ulonglong(len(padded)), nonce, pk, sk))
File "/Users/.../pysodium-0.6.6/pysodium/__init__.py", line 70, in __check
raise ValueError
ValueError