-1

[it automatically detects it as a string`

this is the error

input_msg = input('enter message:-')
        ^
SyntaxError: invalid syntax`]

this is my code

import time
from cryptography.fernet import Fernet
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC

password_provided = "password"  
password = password_provided.encode() 
salt = b'salt_' 
kdf = PBKDF2HMAC(
    algorithm=hashes.SHA256(),
    length=32,
    salt=salt,
    iterations=100000,
    backend=default_backend()
)

key = base64.urlsafe_b64encode(kdf.derive(password)

input_msg = input('enter message:-')

message = input_msg.encode()

time.sleep(15)

f = Fernet(key)

code = f.encrypt(message)

print(message)

i am using vs code and my python version is 3.7 i am unable to use input func and it automatically tells me that my variable is a string as the above image

desertnaut
  • 57,590
  • 26
  • 140
  • 166
  • Please can you post the full stack trace, You say something about a string, but the error you have is a syntax error, not a type error. – Simon Notley May 09 '20 at 17:26
  • A Python syntax error has arguably nothing to do with `cryptography` - kindly do not spam irrelevant tags (removed). – desertnaut May 09 '20 at 21:34
  • Does this answer your question? ['Syntax Error: invalid syntax' for no apparent reason](https://stackoverflow.com/questions/24237111/syntax-error-invalid-syntax-for-no-apparent-reason) – user202729 Jan 20 '21 at 14:10

3 Answers3

1

It looks like you are missing a closing bracket on the line above:

key = base64.urlsafe_b64encode(kdf.derive(password) # need ) here
Paddy Harrison
  • 1,808
  • 1
  • 8
  • 21
0

You're missing a paren on the line above. Should be:

key = base64.urlsafe_b64encode(kdf.derive(password))

Mike
  • 1,471
  • 12
  • 17
0

On this line: key = base64.urlsafe_b64encode(kdf.derive(password) you need to add another ) at the end.

neneko
  • 1
  • 1