[email protected] | 087b8c8 | 2011-04-11 10:28:46 | [diff] [blame^] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 4 | |
5 | #include "base/sha2.h" | ||||
6 | |||||
[email protected] | 087b8c8 | 2011-04-11 10:28:46 | [diff] [blame^] | 7 | #include "base/crypto/secure_hash.h" |
8 | #include "base/scoped_ptr.h" | ||||
[email protected] | e1d6a59 | 2010-09-03 21:02:15 | [diff] [blame] | 9 | #include "base/stl_util-inl.h" |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 10 | |
11 | namespace base { | ||||
12 | |||||
13 | void SHA256HashString(const std::string& str, void* output, size_t len) { | ||||
[email protected] | 087b8c8 | 2011-04-11 10:28:46 | [diff] [blame^] | 14 | scoped_ptr<base::SecureHash> ctx(base::SecureHash::Create( |
15 | base::SecureHash::SHA256)); | ||||
16 | ctx->Update(str.data(), str.length()); | ||||
17 | ctx->Finish(output, len); | ||||
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 18 | } |
19 | |||||
[email protected] | e1d6a59 | 2010-09-03 21:02:15 | [diff] [blame] | 20 | std::string SHA256HashString(const std::string& str) { |
21 | std::string output(SHA256_LENGTH, 0); | ||||
[email protected] | 6c683f0 | 2010-09-24 17:45:21 | [diff] [blame] | 22 | SHA256HashString(str, string_as_array(&output), output.size()); |
[email protected] | e1d6a59 | 2010-09-03 21:02:15 | [diff] [blame] | 23 | return output; |
24 | } | ||||
25 | |||||
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 26 | } // namespace base |