Fedora Linux Support Community & Resources Center
  #1  
Old 22nd January 2012, 01:04 PM
roelj Offline
Registered User
 
Join Date: Jun 2009
Location: Netherlands
Age: 21
Posts: 279
linuxopera
C++ pretty output of SHA 256

I'm facing a problem and I don't know how I can solve it / I don't know where to search.

I'm using botan to generate a SHA-256 check sum and I want it to output it as (I think) modhex.

Though, the output is like:
Code:
L�y�����B��Fs!�)�v&�VG
The output should be something like:
Code:
b8ed91da716fc576e3d005d91a9bdab842288439
I tried using:
Code:
cout << setbase(16) << sha256str << endl;
But it doesn't make a difference at all.

What can I do or what should I know?

---------- Post added at 02:04 PM ---------- Previous post was at 02:56 AM ----------

I should've read more of the Botan documentation. Something like:
Code:
Botan::Pipe pipe(new Botan::Hex_Encoder);
Can convert the output to hexadecimal output.

Now, I wonder, what's the output format of the sha1sum application?
Reply With Quote
  #2  
Old 2nd February 2012, 08:53 PM
RupertPupkin's Avatar
RupertPupkin Offline
Registered User
 
Join Date: Nov 2006
Location: Detroit
Posts: 4,619
linuxfedorafirefox
Re: C++ pretty output of SHA 256

Quote:
Originally Posted by roelj View Post
what's the output format of the sha1sum application?
sha1sum and sha256sum both use hexadecimal output:
Code:
$ echo -n hello | sha1sum -
aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d
$ echo -n hello | sha256sum -
2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824
__________________
OS: Fedora 18 x86_64 | CPU: AMD64 3700+ 2.2GHz | RAM: 2GB PC3200 DDR | Disk: 160GB PATA | Video: ATI Radeon 7500 AGP 64MB | Sound: Turtle Beach Santa Cruz CS4630 | Ethernet: Realtek 8110SC
Reply With Quote
  #3  
Old 3rd February 2012, 01:48 AM
roelj Offline
Registered User
 
Join Date: Jun 2009
Location: Netherlands
Age: 21
Posts: 279
linuxfirefox
Re: C++ pretty output of SHA 256

Thanks for your reply.

I've got the sha256 check sums looking equal to the sha256 software now with the following:
Code:
std::string sha256::process(std::string message) {

  /* Botan pipe to process messages.
   * First make a SHA-256 hash and then apply
   * the hexadecimal format for output on it.
   */
  Botan::Pipe pipe(
    new Botan::Chain(
      new Botan::Hash_Filter(new Botan::SHA_256),
      new Botan::Hex_Encoder)
    );

  pipe.process_msg(message);
  buffer = pipe.read_all_as_string(0);

  boost::to_lower(buffer);
  return buffer;
}
In case anyone is using Botan and Boost as well and wants to get it to work.
Reply With Quote
  #4  
Old 3rd February 2012, 07:58 PM
RupertPupkin's Avatar
RupertPupkin Offline
Registered User
 
Join Date: Nov 2006
Location: Detroit
Posts: 4,619
linuxfedorafirefox
Re: C++ pretty output of SHA 256

Cool, I'd never heard of the Botan library before. For doing that sort of thing programatically I'd used Python:
Code:
>>> import hashlib
>>> print hashlib.sha256("hello").hexdigest()
2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824
Reply With Quote
Reply

Tags
256, cpp, modhex, output, pretty, sha, sha-256

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Pretty trival: tee vs output redirection creeping death Programming & Packaging 4 22nd March 2009 01:21 PM
Sure have a pretty screen! curshe Using Fedora 8 21st January 2009 06:51 PM
Hacked pretty well... netmanwolf Security and Privacy 6 2nd May 2007 07:04 AM
output a file to ternimal but keep the output updated Saint Mike Using Fedora 2 30th December 2006 11:22 AM
Yum seems pretty slow tseliot Fedora Focus 19 24th July 2006 08:24 PM


Current GMT-time: 07:32 (Thursday, 23-05-2013)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat