Skip to content

HMAC digest is incorrect when data contains invalid characters #33

@thedebugger

Description

@thedebugger
require 'openssl'

key = "ss"
data = "\xFF"
algo = OpenSSL::Digest::Digest.new("sha256")

digest1 = OpenSSL::HMAC.digest(algo, key, data)

hmac = OpenSSL::HMAC.new(key, algo)
hmac.update(data)
digest2 = hmac.digest

if digest1 == digest2
  p "digests are equal"
else
  p "digests are not equal"
end

The reason is ruby string is marshalled to java string when appending data into StringBuilder (https://github.com/jruby/jruby-openssl/blob/master/src/main/java/org/jruby/ext/openssl/HMAC.java#L182)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions