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

Using a key version of 5 or higher in conjunction with a random IV is corrupting the header #78

Closed
reidmorrison opened this issue May 26, 2017 · 0 comments
Assignees
Labels

Comments

@reidmorrison
Copy link
Owner

The decrypt fails because the header contains the wrong version number.

e = SymmetricEncryption.cipher(5).encrypt("hello world", true)
SymmetricEncryption.decrypt(e)

Results in

OpenSSL::Cipher::CipherError: bad decrypt
	from /Users/rmorrison/.rvm/gems/ruby-2.3.4/gems/symmetric-encryption-3.9.0/lib/symmetric_encryption/cipher.rb:576:in `final'
	from /Users/rmorrison/.rvm/gems/ruby-2.3.4/gems/symmetric-encryption-3.9.0/lib/symmetric_encryption/cipher.rb:576:in `binary_decrypt'
	from /Users/rmorrison/.rvm/gems/ruby-2.3.4/gems/symmetric-encryption-3.9.0/lib/symmetric_encryption/symmetric_encryption.rb:121:in `decrypt'

Extracting the header:

e = SymmetricEncryption.cipher(5).encrypt("hello world", true)
encoder = SymmetricEncryption.cipher(5).encoder
SymmetricEncryption::Cipher.parse_header!(encoder.decode(e))

Returns the following header which has the wrong version number:

#<SymmetricEncryption::Cipher::HeaderStruct:0x7ff7dc861f60
    cipher_name = nil,
    compressed = false,
    decryption_cipher = #<SymmetricEncryption::Cipher:0x3ffbeb3413a0 @key="[FILTERED]" @iv="ABCDEF1234567890" @cipher_name="aes-256-cbc", @version=2, @encoding=:base64strict, @always_add_header=true,
    iv = "}\xA9k\xB2i\x91pJ\xE9\xAA\x99@\x9F\x84x\x8D",
    key = nil,
    version = 2
>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant