The Crystal Programming Language Forum

Error: undefined method 'hexdigest' for OpenSSL::Digest

Hello! when calling the hexdigest method, I get this error, the error appeared when updating crystal.

def valid_hash?(user : Ledger::User::Abstract) : Bool
      sha = OpenSSL::Digest.new("SHA256")
      sha.update("#{user.hash_seed}")

      user.hash == sha.hexdigest
end

You probably just want to do:

def valid_hash?(user : Ledger::User::Abstract) : Bool
  user.hash == Digest::SHA256.hexdigest(user.hash_seed) 
end

Otherwise, doing user.hash == sha.to_slice.hexstring would also work.

1 Like