-1

This is my protocol:

Encryption and signing - user A

  1. cipher using the public key from user B
  2. sign the encrypted message with the private key A

Verifying and decrypting - user B

  1. verify the signature with the public key A
  2. decrypt the message with the private key B

The private key A and B are the same (128 bit)

I want to send the text using this protocol with AES in mode CBC so i create this code but doesnt work ,apperar in signature:

bytes object has no attribute n

the code is the following:

    def firmar(self, datos):

        try:
            h = SHA256.new(datos)

            signature = pss.new(self.keyprivada).sign(h)
            return signature
        except (ValueError, TypeError):
            return None

    def comprobar(self, text, signature):

        h = SHA256.new(text)

        print(h.hexdigest())
        verifier = pss.new(self.keypublica)
        try:
            verifier.verify(h, signature)
            return True
        except (ValueError, TypeError):
            return False
Doe
  • 21
  • 1
  • 6

1 Answers1

0

This section is no longer relevant as the code has changed

Firstly, you are usine ECB this is insecure due to the relationship between text and its output being constant.

Secondly, CBC requires an IV hence a different implementation would be required.

Lastly and most crucially:

AES is NOT an asymmetric encryption algorithm

meaning that it must be encrypted and decrypted with the same key. You use the public and the private keys as you would with asymmetrical encryption methods.

An alternative:

If you were to implement RSA properly you could then generate a random byte array and use that as your key, then send it encrypted to the recipient to decrypt it and use it as the key to decrypt the aes as it would be the same.

Now:

You use the private key to sign the data... RSA requires you to use the public key (now private - not distributed) to encrypt it however you cannot decrypt something encrypted with the private key with the public key. Instead you distribute the ‘private key’ for decryption and keep the ‘public key’ for encryption so no one else can encrypt or sign the data.

WHAT are you doing!

There is a relationship between public and private keys! You cannot just use random byte arrays.

Read the Wikipedia article.

user6f6e65
  • 146
  • 9
  • The statement of the question is the following :Using as a foundation the previous security protocol, implement a new one where 1) A and B exchange an AES session key of size 128 bits, and then 2) use that session key to send an encrypted text (“Hola amigos de la seguridad”) using any AES operation mode. Compare the size of the ciphertext encrypted with AES in this protocol with the size of the ciphertext encrypted with RSA in the previous protocol, and explain the differences in the source code. – Doe Nov 01 '18 at 22:30
  • Then you’ll need to say it’s symmetrical and ECB pads to the nearest blicksize above it. – user6f6e65 Nov 02 '18 at 07:29
  • Wait, so is that what they give you? If so you’ll need to either call it with (key1,key1) or explicitly set it so in the constructor as it is not public key cryptography. – user6f6e65 Nov 02 '18 at 07:30