blob: e8c922cdf5b1dbf6e6e3849d72af564954d4d0f7 [file] [log] [blame]
[email protected]087b8c82011-04-11 10:28:461// Copyright (c) 2011 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commitd7cae122008-07-26 21:49:384
5#include "base/sha2.h"
6
[email protected]087b8c82011-04-11 10:28:467#include "base/crypto/secure_hash.h"
8#include "base/scoped_ptr.h"
[email protected]e1d6a592010-09-03 21:02:159#include "base/stl_util-inl.h"
initial.commitd7cae122008-07-26 21:49:3810
11namespace base {
12
13void SHA256HashString(const std::string& str, void* output, size_t len) {
[email protected]087b8c82011-04-11 10:28:4614 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.commitd7cae122008-07-26 21:49:3818}
19
[email protected]e1d6a592010-09-03 21:02:1520std::string SHA256HashString(const std::string& str) {
21 std::string output(SHA256_LENGTH, 0);
[email protected]6c683f02010-09-24 17:45:2122 SHA256HashString(str, string_as_array(&output), output.size());
[email protected]e1d6a592010-09-03 21:02:1523 return output;
24}
25
initial.commitd7cae122008-07-26 21:49:3826} // namespace base