1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "crypto/sha2.h" 6 7 #include <stddef.h> 8 9 #include "base/memory/scoped_ptr.h" 10 #include "base/stl_util.h" 11 #include "crypto/secure_hash.h" 12 13 namespace crypto { 14 SHA256HashString(const base::StringPiece & str,void * output,size_t len)15void SHA256HashString(const base::StringPiece& str, void* output, size_t len) { 16 scoped_ptr<SecureHash> ctx(SecureHash::Create(SecureHash::SHA256)); 17 ctx->Update(str.data(), str.length()); 18 ctx->Finish(output, len); 19 } 20 SHA256HashString(const base::StringPiece & str)21std::string SHA256HashString(const base::StringPiece& str) { 22 std::string output(kSHA256Length, 0); 23 SHA256HashString(str, string_as_array(&output), output.size()); 24 return output; 25 } 26 27 } // namespace crypto 28