Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crypto/aes: NewCipher only accept 16 bytes aes key? #9559

Closed
haoxins opened this issue Jan 10, 2015 · 1 comment
Closed

crypto/aes: NewCipher only accept 16 bytes aes key? #9559

haoxins opened this issue Jan 10, 2015 · 1 comment

Comments

@haoxins
Copy link

haoxins commented Jan 10, 2015

use go version - 1.4

According to the doc

  • NewCipher creates and returns a new cipher.Block. The key argument should be the AES key, either 16, 24, or 32 bytes ...

but in the NewCFBEncrypter and NewCBCEncrypter, just compare the length of iv with block.BlockSize(), the return is a const 16.

Because of the iv must be the same length as the Block's block size, the AES key must be 16 bytes?

@minux
Copy link
Member

minux commented Jan 10, 2015

You've confused key and IV, they are not the same thing.
key can be 16/24/32 bytes for AES, but IV must be 16-byte to match the
block size.

http://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#Cipher-block_chaining_.28CBC.29

Working as intended.

@minux minux closed this as completed Jan 10, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants