Skip to content
Snippets Groups Projects
Commit 64df1344 authored by Donald Stufft's avatar Donald Stufft
Browse files

Put the PrivateKey before the PublicKey

parent 45d46448
No related branches found
No related tags found
No related merge requests found
...@@ -56,7 +56,7 @@ with equal that from (pkbob, skalice). This is how the system works: ...@@ -56,7 +56,7 @@ with equal that from (pkbob, skalice). This is how the system works:
# Bob wishes to send Alice an encrypted message # Bob wishes to send Alice an encrypted message
# So Bob must make a Box with his private key and Alice's public key # So Bob must make a Box with his private key and Alice's public key
bob_box = Box(pkalice, skbob) bob_box = Box(skbob, pkalice)
# This is our message to send, it must be a bytestring as Box will # This is our message to send, it must be a bytestring as Box will
# treat is as just a binary blob of data. # treat is as just a binary blob of data.
...@@ -72,7 +72,7 @@ with equal that from (pkbob, skalice). This is how the system works: ...@@ -72,7 +72,7 @@ with equal that from (pkbob, skalice). This is how the system works:
ciphertext = bob_box.encrypt(message, nonce) ciphertext = bob_box.encrypt(message, nonce)
# Alice creates a second box with her private key to decrypt the message # Alice creates a second box with her private key to decrypt the message
alice_box = Box(pkbob, skalice) alice_box = Box(skalice, pkbob)
# Decrypt our message, an exception will be raised if the encryption was # Decrypt our message, an exception will be raised if the encryption was
# tampered with or there was otherwise an error. # tampered with or there was otherwise an error.
......
...@@ -93,18 +93,18 @@ class Box(encoding.Encodable, six.StringFixer, object): ...@@ -93,18 +93,18 @@ class Box(encoding.Encodable, six.StringFixer, object):
send are repudiable. For non-repudiable messages, sign them after send are repudiable. For non-repudiable messages, sign them after
encryption. encryption.
:param public_key: :class:`~nacl.public.PublicKey` used to encrypt and
decrypt messages
:param private_key: :class:`~nacl.public.PrivateKey` used to encrypt and :param private_key: :class:`~nacl.public.PrivateKey` used to encrypt and
decrypt messages decrypt messages
:param public_key: :class:`~nacl.public.PublicKey` used to encrypt and
decrypt messages
:cvar NONCE_SIZE: The size that the nonce is required to be. :cvar NONCE_SIZE: The size that the nonce is required to be.
""" """
NONCE_SIZE = nacl.lib.crypto_box_NONCEBYTES NONCE_SIZE = nacl.lib.crypto_box_NONCEBYTES
def __init__(self, public_key, private_key): def __init__(self, private_key, public_key):
if public_key and private_key: if private_key and public_key:
_shared_key_size = nacl.lib.crypto_box_BEFORENMBYTES _shared_key_size = nacl.lib.crypto_box_BEFORENMBYTES
_shared_key = nacl.ffi.new("unsigned char[]", _shared_key_size) _shared_key = nacl.ffi.new("unsigned char[]", _shared_key_size)
......
...@@ -37,7 +37,7 @@ def test_box_encryption(skalice, pkalice, skbob, pkbob, nonce, plaintext, cipher ...@@ -37,7 +37,7 @@ def test_box_encryption(skalice, pkalice, skbob, pkbob, nonce, plaintext, cipher
pkalice = PublicKey(pkalice, encoder=HexEncoder) pkalice = PublicKey(pkalice, encoder=HexEncoder)
skbob = PrivateKey(skbob, encoder=HexEncoder) skbob = PrivateKey(skbob, encoder=HexEncoder)
box = Box(pkalice, skbob) box = Box(skbob, pkalice)
plaintext = binascii.unhexlify(plaintext) plaintext = binascii.unhexlify(plaintext)
nonce = binascii.unhexlify(nonce) nonce = binascii.unhexlify(nonce)
...@@ -50,7 +50,7 @@ def test_box_decryption(skalice, pkalice, skbob, pkbob, nonce, plaintext, cipher ...@@ -50,7 +50,7 @@ def test_box_decryption(skalice, pkalice, skbob, pkbob, nonce, plaintext, cipher
pkbob = PublicKey(pkbob, encoder=HexEncoder) pkbob = PublicKey(pkbob, encoder=HexEncoder)
skalice = PrivateKey(skalice, encoder=HexEncoder) skalice = PrivateKey(skalice, encoder=HexEncoder)
box = Box(pkbob, skalice) box = Box(skalice, pkbob)
nonce = binascii.unhexlify(nonce) nonce = binascii.unhexlify(nonce)
decrypted = binascii.hexlify( decrypted = binascii.hexlify(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment