OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/sha1.h" | 5 #include "base/sha1.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 #include <wincrypt.h> | 8 #include <wincrypt.h> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/string_util.h" | |
12 | 11 |
13 namespace base { | 12 namespace base { |
14 | 13 |
15 // Implementation of SHA-1 using Windows CryptoAPI. | 14 // Implementation of SHA-1 using Windows CryptoAPI. |
16 | 15 |
17 // Usage example: | 16 // Usage example: |
18 // | 17 // |
19 // SecureHashAlgorithm sha; | 18 // SecureHashAlgorithm sha; |
20 // while(there is data to hash) | 19 // while(there is data to hash) |
21 // sha.Update(moredata, size of data); | 20 // sha.Update(moredata, size of data); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 | 105 |
107 std::string SHA1HashString(const std::string& str) { | 106 std::string SHA1HashString(const std::string& str) { |
108 SecureHashAlgorithm sha; | 107 SecureHashAlgorithm sha; |
109 sha.Update(str.c_str(), str.length()); | 108 sha.Update(str.c_str(), str.length()); |
110 sha.Final(); | 109 sha.Final(); |
111 std::string out(reinterpret_cast<const char*>(sha.Digest()), SHA1_LENGTH); | 110 std::string out(reinterpret_cast<const char*>(sha.Digest()), SHA1_LENGTH); |
112 return out; | 111 return out; |
113 } | 112 } |
114 | 113 |
115 } // namespace base | 114 } // namespace base |
OLD | NEW |