From: Alex Young Date: 2011-08-04T19:25:52+09:00 Subject: [ruby-core:38783] [Ruby 1.8 - Bug #5156] Problem with creating a SHA2 digest hash when string has character sequence "#$" Issue #5156 has been updated by Alex Young. This is a problem of string interpolation, not SHA: ruby-1.9.2-p290 :002 > s="968901L#$q675PwX" => "968901L" ruby-1.9.2-p290 :003 > t='968901L#$q675PwX' => "968901L\#$q675PwX" ruby-1.9.2-p290 :004 > Digest::SHA2.new.update(s).hexdigest => "6b9139de7a8d0e7436e98a4e39317e54642f2e4185c31c9395ce7a12cfd56627" ruby-1.9.2-p290 :005 > Digest::SHA2.new.update(t).hexdigest => "6659bd73f7295ee5ddc35dc03e46274e30c2488bacd4f7d4926e5649202918b9" As such, you should only observe this on double-quoted literal strings. ---------------------------------------- Bug #5156: Problem with creating a SHA2 digest hash when string has character sequence "#$" http://redmine.ruby-lang.org/issues/5156 Author: Martin Ceronio Status: Open Priority: Normal Assignee: Category: Target version: ruby -v: ruby 1.8.7 (2010-08-16 patchlevel 302) [i686-linux], ruby 1.8.7 (2010-01-10 patchlevel 249) [i386-mingw32] When calculating a SHA2 hash in Ruby using Digest::SHA2, it gives weird results. Consider the following string: "968901L#$q675PwX" which has a SHA2 hash of 6659bd73f7295ee5ddc35dc03e46274e30c2488bacd4f7d4926e5649202918b9 (confirmed with http://www.xorbin.com/tools/sha256-hash-calculator and ABAP language as well). Using Digest::SHA2 in Ruby, the hash is 6b9139de7a8d0e7436e98a4e39317e54642f2e4185c31c9395ce7a12cfd56627. Where things seem to fall apart is from the hash and dollar sign ("#$") onwards. If you try hash a string ending in "#$" with Digest::SHA2, it gives an exception in Ruby ("unterminated string meets end of file"). Tested under Windows and Linux with Ruby 1.8.7. Specifically: ruby 1.8.7 (2010-08-16 patchlevel 302) [i686-linux] ruby 1.8.7 (2010-01-10 patchlevel 249) [i386-mingw32] -- http://redmine.ruby-lang.org