1

I am taking in user input and need to turn it into an AES encryption key. I have:

keyInput= input("Enter key:")
key = keyInput.encode()
print(key)

If I type in "computer" for the input. I get the result b'computer' for the output.

Shouldn't it look something more like this?

b'\xbf\xc0\x85)\x10nc\x94\x02)j\xdf\xcb\xc4\x94\x9d(\x9e[EX\xc8\xd5\xbfI{\xa2$\x05(\xd5\x18'
4
  • Hashing and encryption are different things. The former should be used for password storage and verification (with more specific requirements); the latter should not. Commented Nov 15, 2020 at 1:47
  • I have edited the post and would love some input. Thanks in advance Commented Nov 15, 2020 at 1:49
  • 1
    Please read How to Ask, then edit your question to provide sufficient context. Ideally, you should give us a minimal reproducible example. Commented Nov 15, 2020 at 1:53
  • Sorry, very new to stack. Commented Nov 15, 2020 at 1:58

2 Answers 2

2

"computer" cannot be an AES key because it only consists of ASCII characters. Keys for algorithms such as AES should consist of fully randomized bits and of course of a specific size (128, 192 or 256 bits).

What you are after is password based encryption. For this there are standards, such as PKCS#5, literally the "Password-Based Cryptography Specification" (Version 2.1). Basically it uses PBKDF2 to calculate a key from a relatively weak password using a salt and a work factor (or, in the case of PBKDF2, an iteration count).

Sign up to request clarification or add additional context in comments.

Comments

2

Long answer: https://crypto.stackexchange.com/questions/53552/aes-with-small-and-large-string-keys

Short answer. AES takes a 128-bit, 192-bit, or 256-bit key. Some APIs let you use a password instead of a key. How the password gets converted into the appropriate length key is not part of the AES standard. There are a large number of "Password Based Key Derivation Functions" (PBKDF) that perform this function.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.