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/crypto/encryptor.h" | 5 #include "base/crypto/encryptor.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/crypto/symmetric_key.h" | 9 #include "base/crypto/symmetric_key.h" |
10 | 10 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 &data_len, total_len); | 86 &data_len, total_len); |
87 if (!ok) | 87 if (!ok) |
88 return false; | 88 return false; |
89 | 89 |
90 ciphertext->assign(reinterpret_cast<char*>(&tmp[0]), data_len); | 90 ciphertext->assign(reinterpret_cast<char*>(&tmp[0]), data_len); |
91 return true; | 91 return true; |
92 } | 92 } |
93 | 93 |
94 bool Encryptor::Decrypt(const std::string& ciphertext, std::string* plaintext) { | 94 bool Encryptor::Decrypt(const std::string& ciphertext, std::string* plaintext) { |
95 DWORD data_len = ciphertext.size(); | 95 DWORD data_len = ciphertext.size(); |
| 96 if (data_len == 0) |
| 97 return false; |
96 | 98 |
97 std::vector<BYTE> tmp(data_len); | 99 std::vector<BYTE> tmp(data_len); |
98 memcpy(&tmp[0], ciphertext.data(), data_len); | 100 memcpy(&tmp[0], ciphertext.data(), data_len); |
99 | 101 |
100 BOOL ok = CryptDecrypt(capi_key_.get(), NULL, TRUE, 0, &tmp[0], &data_len); | 102 BOOL ok = CryptDecrypt(capi_key_.get(), NULL, TRUE, 0, &tmp[0], &data_len); |
101 if (!ok) | 103 if (!ok) |
102 return false; | 104 return false; |
103 | 105 |
104 DCHECK_GT(tmp.size(), data_len); | 106 DCHECK_GT(tmp.size(), data_len); |
105 | 107 |
106 plaintext->assign(reinterpret_cast<char*>(&tmp[0]), data_len); | 108 plaintext->assign(reinterpret_cast<char*>(&tmp[0]), data_len); |
107 return true; | 109 return true; |
108 } | 110 } |
109 | 111 |
110 } // namespace base | 112 } // namespace base |
OLD | NEW |