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 <memory> 10 11 #include "base/stl_util.h" 12 #include "crypto/secure_hash.h" 13 14 namespace crypto { 15 SHA256HashString(base::StringPiece str,void * output,size_t len)16void SHA256HashString(base::StringPiece str, void* output, size_t len) { 17 std::unique_ptr<SecureHash> ctx(SecureHash::Create(SecureHash::SHA256)); 18 ctx->Update(str.data(), str.length()); 19 ctx->Finish(output, len); 20 } 21 SHA256HashString(base::StringPiece str)22std::string SHA256HashString(base::StringPiece str) { 23 std::string output(kSHA256Length, 0); 24 SHA256HashString(str, base::data(output), output.size()); 25 return output; 26 } 27 28 } // namespace crypto 29