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

PKI.encrypt(): missing padding block when last block is full #8

Closed
hadley opened this issue Oct 6, 2014 · 2 comments
Closed

PKI.encrypt(): missing padding block when last block is full #8

hadley opened this issue Oct 6, 2014 · 2 comments

Comments

@hadley
Copy link

hadley commented Oct 6, 2014

key <- "abcdef"
ser <- serialize(list(x = 1), connection = NULL)

enc <- PKI::PKI.encrypt(ser, key, "AES-256")
dec <- PKI::PKI.decrypt(enc, key, "AES-256")

all.equal(ser, dec)
#> [1] "Lengths (80, 64) differ (comparison on first 64 components)"
all.equal(ser[1:64], dec)
#> [1] TRUE
@s-u s-u changed the title Decryption loses some trailing bytes? PKI.encrypt(): missing padding block when last block is full Oct 7, 2014
@s-u
Copy link
Owner

s-u commented Oct 7, 2014

This shows two bugs: first, the key is way too short (must be 32 bytes for AES-256) but it was not detected. second, when the payload is exactly multiple of the block size, the padding block was not generated, so decoding fails to finalize the last bock. So now this should work:

key <- PKI::PKI.digest("abcdef", "SHA256")
ser <- serialize(list(x = 1), connection = NULL)

enc <- PKI::PKI.encrypt(ser, key, "AES-256")
dec <- PKI::PKI.decrypt(enc, key, "AES-256")

all.equal(ser, dec)
#> [1] TRUE

@s-u s-u closed this as completed in 3412fef Oct 7, 2014
@hadley
Copy link
Author

hadley commented Oct 7, 2014

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants